[mod_python] My template script isn't working

Jim Gallacher jg.lists at sympatico.ca
Sun Aug 28 19:45:47 EDT 2005


Graham Dumpleton wrote:
> 
> On 29/08/2005, at 8:49 AM, Anton wrote:
> 
>> I am migrating from php to python. Simple script are attached with  
>> templates.
>>
>> The problem is script isn't being processed by apache (It's not
>> AddHandler stuff). And I think something is segfaulting.
>>
>> What is wrong with it?
>>
>> Script works if I, for example, change QUOTE to QUOTE2 and error  occurs:
>> NameError: name 'QUOTE' is not defined
>> <index.py><style.css><header.tmpl><index.tmpl><right.tmpl>_____________ 
>> _________________________________
> 
> 
> In your code you have:
> 
>   from mod_python import apache,psp
> 
>   def index(req):
>     quote = 'quote_of_the_day'
>     tmpl = psp.PSP(req, filename='templates/index.tmpl')
>     tmpl.run( vars={'QUOTES':quote} )
>     return apache.OK
> 
> The current working directory will not be that of your script. For
> starters, try instead:
> 
>   from mod_python import apache,psp
> 
>   import os
> 
>   __here__ = os.path.dirname(__file__)
> 
>   def index(req):

       req.content_type = 'text/html'

>     quote = 'quote_of_the_day'
>     tmpl = psp.PSP(req, filename=os.path.join(__here__,'index.tmpl'))
>     tmpl.run( vars={'QUOTES':quote} )
>     return apache.OK

Using Graham's suggestion plus setting the content_type and changing 
QUOTES to QUOTE worked fine for me with your templates using mod_python 
3.2.1b and Firefox. I suggest try using the simplest possible template 
that works and build out from there to find the error.

Jim


More information about the Mod_python mailing list