[mod_python] PSP imports

Gregory (Grisha) Trubetskoy grisha at modpython.org
Tue Nov 25 21:45:35 EST 2003

One of the ways to use PSP, which probably isn't immediately obvious from
the documentation, is as a templating system, e.g. configuring mod_python
to use the publisher handler, then have something like:

def hello(req):

    vars = {"menu": build_menu(),
            "blah": enormously_complex_function(),
            "body": psp.PSP(req, 'templates/body_tmpl.html')}

    return psp.PSP(req, 'templates/main_frame.html', vars=vars)

In this example 'body_tmpl.html' and 'main_fram.html' are PSP.

I've had pretty good luck with this approach precisely because it seems to
have a clear separation of logic and presentation.


On Mon, 24 Nov 2003, Michael S. Fischer wrote:

> Dan W. wrote:
> > That's a good point Michael.  That was probably a bad habit to pick up.
> > However, I think a overloaded import could still be useful.  Overloading
> > the builtin import would allow a PSP file to control autoreloading for
> > its entire dependency tree (modules which call other modules, etc.).
> > This would allow one to easily turn autoreloading on during development
> > and to easily turn it off for production deployment.
> Consider that you might want not to use PSP.  I've actually found that
> it gets in the way of the separation of code and content, which is
> important when the designer and the coder are two different people.
> I design my mod_python apps like so:
> template = """
> <html>
> ...
> <!-- have the designers place %(variable)s where necessary
>       in the template for doing performing substitution
>       during the processing phase -->
> </html>
> """
> def handler(req):
>    # Reload modules here if necessary
>    # Code goes here
>    # If you want to override the template, you can fetch it from the file
>    # system
>    req.write(template % vars())
> Of course, if you're already married to the PSP solution, then there you
> have it...
> --Michael
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list