[mod_python] My template script isn't working

Anton selecter at gmail.com
Mon Aug 29 04:49:37 EDT 2005


Thanks, Graham, for so detailed explanation. I think your suggestion
has just worked. I also had random errors like "psp cannot be
imported".

2005/8/29, Graham Dumpleton <grahamd at dscpl.com.au>:
> Anton wrote ..
> >         <Directory /home/anton/homepage>
> >                 AddHandler mod_python .py .spy .psp
> >                 PythonHandler mod_python.publisher | .py
> >                 PythonHandler spyce.run_spyceModpy::spyceMain | .spy
> >                 PythonHandler mod_python.psp | .psp
> >                 PythonDebug On
> >                 Options Indexes FollowSymLinks MultiViews
> >                 AllowOverride None
> >                 Order allow,deny
> >                 allow from all
> >         </Directory>
> >
> > ...
> >
> > > index.py:
> > > from mod_python import apache,psp
> > > import os
> > >
> > > def index(req):
> > >         req.content_type = 'text/html'
> > >         quote = 'quote_of_the_day'
> > >         tmpl = psp.PSP(req, filename='templates/dummy.tmpl')
> > >         tmpl.run( vars={'QUOTE':quote} )
> > >         return apache.OK
> 
> Something else to be careful of, there is a bug in mod_python (fixed in 3.2),
> whereby:
> 
>   from mod_python import psp
> 
> will not always work if you also have:
> 
>   PythonHandler mod_python.psp | .psp
> 
> and a .psp file is accessed directly before the handler which tries to import the
> psp module.
> 
> Use the following instead:
> 
>   psp = apache.import_module("mod_python.psp")
> 
> None of the things I have mentioned may be your real problem, but they
> should at least make your code a bit more robust in the bigger scheme
> of things.
> 
> Graham
>



More information about the Mod_python mailing list