Graham Dumpleton
grahamd at dscpl.com.au
Mon Nov 14 20:58:29 EST 2005
Bjorn Sundberg wrote .. > Hello i'm quite new to mod_python. I've read the documents on the net and > i > found that the templating system is quite interesting. My problem is that > i'm trying to load dynamic data in a template. And when the program runs > it > loads and repeat the template file and the variables that i want to change. > So far so good, but i'm only intrested in changing the psp variables in > the > file. It seem's that i is not possible to use the <%# Stop %> to prevent > the > <p> to repeat. Any body that have any ideas? Thanks in advance. > > Regards > Björn S > --Code-- > #!/usr/bin/env python > from mod_python import psp > > def index(req): > req.add_common_vars() > req.content_type='text/html;charset=utf-8' > tmpl = psp.PSP(req, filename='3-2.html') > for key in req.subprocess_env.keys(): > tmpl.run(vars = {'key': key, 'env': req.subprocess_env[key]}) This is going to render the template multiple times, you probably just want: from mod_python import psp def index(req): req.add_common_vars() req.content_type='text/html;charset=utf-8' tmpl = psp.PSP(req, filename='3-2.html') #for key in req.subprocess_env.keys(): # tmpl.run(vars = {'key': key, 'env': req.subprocess_env[key]}) tmpl.run() > --end-- > ---template--- > <html> > <head> > <title> > 3-2.py > </title> > </head> > <body> > <table > > <td><%=key %></td> > <td><%=env %></td> > </tr> > </table> > <p>test</p> > </body> > </html> Then in your template use: <html> <head> <title> 3-2.py </title> </head> <body> <table > <% for key in req.subprocess_env.keys(): # indent %> <tr> <td><%=key%></td> <td><%=req.subprocess_env[key]%></td> </tr> <% # end for %> </table> <p>test</p> </body> </html> Watch out for indenting issues. Graham
|