Anton
selecter at gmail.com
Sun Aug 28 20:22:46 EDT 2005
I place this script in /home/anton/homepage/py-homepage $ cat /etc/apache2/sites-enabled/000-default NameVirtualHost localhost <VirtualHost localhost> ServerAdmin selecter at gmail.com DocumentRoot /home/anton/homepage <Directory /> Options FollowSymLinks AllowOverride None </Directory> <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> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel debug CustomLog /var/log/apache2/access.log combined ServerSignature On Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost> 2005/8/29, Anton <selecter at gmail.com>: > Ok. But it didn't work as well. > > dummy.tmpl: > <html> > <%=QUOTE%> > </html> > > 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 > > > I noticed strange behavior on step 3... > 1. Page didn't load as expected > > 2. I changed > tmpl.run( vars={'QUOTE':quote} ) > to > tmpl.run( vars={'QUOTEeeee':quote} ) > > and I could see errors ending with: NameError: name 'QUOTE' is not defined > > 3. I reloaded page and saw the same thing + new string in the middle: > File "/home/anton/homepage/py-homepage/index.py", line 8, in index > tmpl.run( vars={'QUOTEeee':quote} ) > > 4. Changed QUOTEeeee to QUOTE, reloaded page and it worked: > > quote_of_the_day 0 > > Then I returned to step 2 and all went again. > > I am running Debian sarge with: > python 2.3.5-2 > libapache2-mod-python2.3 3.1.3-3 > apache2 2.0.54-4 > mozilla-firefox 1.0.4-2sarge2 > > 2005/8/29, Jim Gallacher <jg.lists at sympatico.ca>: > > 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 > > >
|