[mod_python] PSP Templating

John_Nowlan john_nowlan at carleton.ca
Thu Mar 1 10:09:54 EST 2007


I think you need to set the content type of your page. I.e. put

       req.content_type = 'text/html'

as the first line of your hello function.
See the mod_python faq 2.25. as well
http://www.modpython.org/FAQ/faqw.py?req=show&file=faq02.025.htp


> -----Original Message-----
> From: mod_python-bounces at modpython.org
> [mailto:mod_python-bounces at modpython.org]On Behalf Of John Ruff
> Sent: Thursday, March 01, 2007 9:40 AM
> To: mod_python
> Subject: [mod_python] PSP Templating
> 
> 
> I'm trying to understand what I'm doing wrong.  I'm using mod_python  
> 3.3.1 with apache 2.2.4.  The situation is that while trying to use  
> PSP as a templating engine, none of the examples work.  Yet normal  
> 'SetHandler mod_python' with inline html works no problem.
> 
> I have the following:
> 
> <Directory "/home/<user-dir>/Sites/python">
>      SetHandler mod_python
>      PythonHandler mod_python.publisher
>      PythonOption mod_python.psp.cache_database_filename "/tmp/ 
> pspcache.dbm"
>      PythonDebug On
> </Directory>
> 
> ====hello.py====
> from mod_python import apache, psp
> 
> def hello(req):
>      s = 'Hello, there!'
>      tmpl = psp.PSP(req, filename = 'hello.tmpl')
>      tmpl.run(vars = {'greet':s})
>      return apache.OK
> 
> ====hello.tmpl====
> <html>
> <body>
>      <h1><%=greet%></h1>
> </body>
> </html>
> 
> 
> Still, I'm presented with a webpage that's raw html of what would  
> have been generated.  When using firefox's Web Developer toolbar to  
> see the generated source I can see that my html has been surrounded  
> by an '<html><head></head><body><pre>...</pre></body></html>' 
> block.   
> So it looks like this:
> 
> [snip]
> 
> <html><head></head><body><pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD  
> XHTML 1.0 Strict//EN"
>      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
> 
> &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"  
> lang="en"&gt;
> &lt;head&gt;
>      &lt;meta http-equiv="Content-Type" content="text/html;  
> charset=utf-8"/&gt;
> 
>      &lt;title&gt;hello&lt;/title&gt;
> 
> 
> &lt;/head&gt;
> 
> &lt;body&gt;
>      &lt;h1&gt;Hello, there!&lt;/h1&gt;
> &lt;/body&gt;
> &lt;/html&gt;
> </pre></body></html>
> 
> [/snip]
> 
> Any ideas why this is happening?
> ___________________
> John Ruff
> jcruff at gmail.com
> GPG Key: 0x1F691195
> FGPR: 6B50 37C9 10F9 6C4A D381  54B8 319D 7DD9 1F69 1195
> 
> "No one can see past a choice they don't understand." --The Oracle
> 
> 
> _______________________________________________
> 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