[mod_python] Redirect and/or output regeneration with PSP files

Anastasios Hatzis (Hatzis Edelstahlbearbeitung) ah at hatzis.de
Tue May 30 16:40:17 EDT 2006


Jim Gallacher wrote:
> mptest.py
> ---------
> def index(req):
>     vars = {}
>     if some_condition:
>         vars['body'] = psp.PSP(req, filename='hi.tmpl')
>     else:
>         vars['body'] = psp.PSP(req, filename='bye.tmpl')
>
>     master_tmpl = psp.PSP(req, filename='master.tmpl', vars=vars)
>     return master_tmpl
>
>
> master.tmpl
> -----------
> <html>
> <body>
> <%= body %>
> </body>
> </html>
>
> hi.tmpl
> ---------
> <p>Hello world</p>
>
> bye.tmpl
> --------
> <p>Goodbye world</p>
>
>
> When <%= body %> is encountered it's __str__ method is called. For a 
> PSP instance this causes body.run() to be called. If you need access 
> to vars in the sub-templates you'll need to pass vars to each in their 
> constructors.
>
Yes, this pattern seems to work fine for me. I adopted it for my 
environment and it's wonderful. Meets both requirements and I still take 
benefit from the PSP-features. Thank you also for clarifying the PSP 
behaviour.

>> Many thanks again and greetings from southern Germany (snowing here, 
>> hurrrr)
> Now *that* is just crazy. (The snow part, not the fact that you are 
> from Southern Germany. ;) )
It's a nightmare! Over last night all of my mom's flowers have been 
assassinated perfidously. My old tomcat Herr Hugo impends to change back 
again to winter pelt. I want it to stop. I already shot dozens of 
lovely-boring winter landscape photos since I moved into this region. 
It's enough. Whoever guilty: Give us back the spring!

Anastasios
...waiting for the real summer.


More information about the Mod_python mailing list