[mod_python] mod_python.publisher weirdness

Jorey Bump list+mod_python at joreybump.com
Wed Apr 14 11:33:56 EST 2004

Jeff Hinrichs wrote:

> mod_python: 3.1.3
> OS: FreeBSD 4.9 Stable
> Apache: Apache/2.0.49 (Unix) mod_python/3.1.3 Python/2.3.3
> httpd.conf:
> <Directory "/usr/local/www/data/mrt">
>     SetHandler mod_python
>     PythonHandler mod_python.publisher
>     PythonDebug On
> </Directory>
> <Directory "/usr/local/www/data/mrtJDB">
>     SetHandler mod_python
>     PythonHandler mod_python.publisher
>     PythonDebug On
> </Directory>
> I have an index.py in each of the two directories.  On both pages a link to
>  http://mysite/mrt/  exists.
> I must be doing something very wrong but I'm just not seeing it right now.

You're thinking of your files as pages instead of python modules. It's 
important that all of your modules have unique names or you will 
encounter conflicts, since they share one interpreter. Rename one of the 
modules to index2.py, and you may see the problem disappear.

For this reason, you should avoid setting your DirectoryIndex to a 
python module (index.py). Use a gateway index.html page, instead, or 
link directly to the python file.

mod_python doesn't use the file hierarchy to isolate modules or 
applications. Personally, I've found this to be an enormous strength, as 
it allows you to easily reuse code. It does draw extra attention to the 
security implications of a shared hosting environment, however, which 
affects all embedded interpreters. The nice thing about mod_python is 
that it spawns an interpreter for each virtual host (so I understand), 
so you're not completely at the mercy of another developer using the 
same instance of apache.

I'm a python/mod_python newbie, myself, so others may want to clarify or 
correct my comments. I ran into name conflicts immediately, and the 
simple solution actually encourages good programming discipline (not 
unlike indentation, another initial stumbling block that you grow to love).

More information about the Mod_python mailing list