[mod_python] PSP Templating printing in plain text

Nicolas Lehuen nicolas.lehuen at gmail.com
Tue Nov 22 08:19:49 EST 2005


Hi Matt,

Looks like your browser doesn't recognize the document as HTML. Try to
set the Content-Type header of the response :

def hello(req, name=''):
   s = 'Hello, there!'
   if name:
       s = 'Hello, %s!' % name.capitalize()

   # Here it is
   req.content_type = 'text/html'

   tmpl = psp.PSP(req, filename='hello.tmpl')
   tmpl.run(vars = { 'greet': s })
   return

Regards,
Nicolas


2005/11/22, Matt Shaw <matt.shaw at elanit.co.uk>:
>
> I have been playing with Python for making a web project, mainly to learn
> the Python language and realised that the most painful part of it all was
> not the Python at all but the CGI, so found MOD_PYTHON and am going to use
> this as seems perfect.  However when following the example below, it outputs
> to the browser as plain text with all the tags shown and not as tho its
> HTML, I'm using the Ubuntu 5.10.  Oddly enough it does actually swap out the
> variable, so it is kinda working :-) Any help would be appreciated.
>
>
>
> Here is a snippet of the relevant Apache configuration for using the
> Publisher:<Directory /your/document/root>
> SetHandler mod_python
> PythonHandler mod_python.publisher
> PythonDebug On
> </Directory>
>
>
> Since we're using PSP as a templating mechanism, we need a template. Let's
> assume it is in a file named /your/document/root/hello.tmpl:<html>
>  <h1><%= greet %></h2>
> </html>
>
>
> Here is the Python script. Let's assume it is in a file called
> /your/document/root/pubpsp.py.from mod_python import psp
>
> def hello(req, name=''):
>  s = 'Hello, there!'
>  if name:
>  s = 'Hello, %s!' % name.capitalize()
>
>  tmpl = psp.PSP(req, filename='hello.tmpl')
>  tmpl.run(vars = { 'greet': s })
>  return
>
>  -
> ---------------------------------------------------------------------
>  Elan is the world's leading IT&T recruitment company. For more information
> go to www.ElanIT.com.
>
>  -
> ---------------------------------------------------------------------
>  The contents of this email and any attachment are confidential to the
> addressee and are intended solely for the addressee's use. If you are not
> the addressee, you have received this email in error. If so, you must not
> disclose, copy or take any action in reliance on this email and any
> attachment. If you received this in error, please contact the sender and
> delete the material from your computer.
>
>  Although this email and any attachment have been checked for viruses, no
> liability is accepted by Elan in this regard. The recipient should carry out
> virus and other checks as it deems necessary to ensure that this email and
> any attachments will not adversely affect its systems or data.
>
> _______________________________________________
> 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