[mod_python] combine psp with publisher woes

Graham Dumpleton grahamd at dscpl.com.au
Thu Aug 11 17:39:09 EDT 2005


On 11/08/2005, at 11:29 PM, km wrote:

>
> Hi all,
> i have tried  the classic example which separates template from logic.
> i am using mod_python 3.14 with apache 2.0.54
>
> # template ->  hello.template
> <html>
> <h1><%= greet %></h2>
> </html>
>
> # script hello2.py
> from mod_python import apache, psp
> def handler(req):
>     tmpl = psp.PSP(req, filename='./hello.template')
>     tmpl.run(vars = {'greet': 'world'})
>     return  apache.OK
> i have placed both hello2.py and hello.template in  
> /usr/local/apache2/htdocs/test1 dir.

The above is not quite written in style required by publisher.
A publisher function to be able to automatically determine
content type needs content to be the return value of the function.
Here the PSP object writes directly to the req object. Thus use:

from mod_python import apache, psp
def handler(req):
     req.content_type = 'text/html'
     tmpl = psp.PSP(req, filename='./hello.template')
     tmpl.run(vars = {'greet': 'world'})
     return " "

and the URL:

   http://myhost/test1/hello2.py/handler

And yes I do mean to return a string containing one space. This is to
stop publisher return a 500 error if None is returned. Don't think this
problem is in latest 3.2 code though. Returning None is okay provided
there has been content previously written to req object in 3.2.

Graham



More information about the Mod_python mailing list