[mod_python] questions about mod_python publisher

Volodya volodya at real.samuraj.org
Thu May 20 11:51:00 EDT 2004


On Wed, May 19, 2004 at 06:56:02PM +0100, Terry MacDonald wrote:
> On Wed, 2004-05-19 at 18:27, Jorey Bump wrote:
> > I don't need to use the suffix. My httpd.conf looks like this (Debian 
> > Woody: apache 1.3.26, mod_python 2.7.8):
> > 
> > <Directory /var/www/documentroot>
> >    AddHandler python-program .py
> >    PythonHandler mod_python.publisher
> >    PythonDebug On
> > </Directory>
> > 
> > I can access function foobar in app.py like this:
> > 
> >   http://www.example.com/app/foobar
> 
> 
> Well something is different because with this config (i'm not an apache
> expert):
> 
> (Using Fedora Core 1, apache 2.0.48 and mod_python 3.1.3)
> 
> PythonDebug on
>  
> <Directory "/var/www/python">
>     PythonPath "['/var/www/python']+sys.path"
>     AddHandler mod_python .py
>     PythonHandler mod_python.publisher
>     Options None
>     AllowOverride None
>     Order allow,deny
>     Allow from all
> </Directory>
> 
> my foobar in app.py called as http://localhost/app/foobar gives a 'Not
> Found' error while http://localhost/app.py/foobar works fine.
> 
> This is an ongoing bugbear for me: dropping the .py.  Can anyone explain
> this odd behaviour, Grisha?
> 

Under Apache 2 , you MUST use "SetHandler mod_python". By this, you're
telling Apache to direct all requests (in this dir) to mod_python
module. And by specifying "PythonHandler mod_python.publisher" , your're
telling mod_python to use publisher handler.

So when you're accessing http://localhost/app/foobar , Apache directs
this request to mod_python. Mod_python uses publisher-handler logic to
process this request. This page explains traversal logic:

http://www.modpython.org/live/current/doc-html/hand-pub-alg-trav.html

Quote :
  If req.filename is empty, the module name defaults to "index".

So publisher-handler will try to import index.py module , and execute
its foobar() function.

In your case :
  You have no SetHandler directive , so Apache directs only *.py
  requests to mod_python module.

So:
  http://localhost/app.py/foobar  , passes to mod_python
  
  and
  
  http://localhost/app/foobar is served by Apache itself wich
  produces 404 error.



P.S. As far as i know, SetHandler/AddHandler behavior
is slightly different in Apache 1.3 and Apache 2.


Hope this helps.


More information about the Mod_python mailing list