[mod_python] newb question on apache conf

Jorey Bump list at joreybump.com
Fri Feb 25 09:26:02 EST 2005


Nicolas Lehuen wrote:
> On Fri, 25 Feb 2005 14:36:10 +0000 (GMT), lafras at sun.ac.za
> <lafras at sun.ac.za> wrote:
>>when opening up a *.py script in my browser, everything works fine and
>>apache displays what it should, however when i try open a *.html file, i
>>get this error,
> 
> If you use the SetHandler directive, each and every request is handled
> by mod_python, which then uses mod_python.publisher to publish
> something according to the request. So with the setup you describe,
> even a request for an html page is handled by the publisher, which
> does not find anything to do with the URL it is provided.
> 
> A simple solution is simply to tell Apache to use mod_python only for
> .py files ; for this you use the AddHandler directive instead of the
> SetHandler one :
> 
> AddHandler mod_python .py
> 
> instead of :
> 
> SetHandler mod_python

As Nicolas says, AddHandler allows you to mix file types and works very 
well. However, you may lose the ability to hide the .py extension in 
your URLs. Assuming a published module in the apps directory, with the 
name foo.py that has a function named bar, SetHandler allows this:

  http://example.com/apps/foo/bar

while AddHandler generally permits only this:

  http://example.com/apps/foo.py/bar

Many people prefer the hidden extension for aesthetic reasons and to 
obscure the type of web technology used. While you may be able to 
achieve the same result with AddHandler and MultiViews, this introduces 
its own set of potential problems.

While you are getting used to the idiosyncracies of Publisher, you may 
want to use SetHandler and put *all* of your published modules in one 
directory (like the apps directory mentioned above) and your non-Python 
resources elsewhere. This will help you to avoid common mistakes made by 
beginners and steer you towards developing a structure that works best 
with Publisher.



More information about the Mod_python mailing list