[mod_python] Problem with mapping URIs to filesystem/Python modules

Fabian Fagerholm fabbe at paniq.net
Wed May 12 23:55:58 EDT 2004

On Wed, 2004-05-12 at 16:57, Manfred Stienstra wrote:
> You can let python handle all the request on a path:
> SetHandler python-program
> PythonHandler handler
> This will call handler.py - handler(req) for every request on this path.
> If you don't want to call your handler handler:
> PythonHandler myhandlerfilename:myhandlerfunctionname

Ok, this works nicely, and I can override it for subdirectories by their
own .htaccess files, I presume.

> If you still want to serve real files from this path, just return
> apache.DECLINED from your handler and apache will retry the request with
> the core handler.

This doesn't seem to work. It does work with AddHandler, but if I use
SetHandler and return apache.DECLINED, then I only get a 404 not found
error. I presume this is because SetHandler overrides all other handlers
and there are no other handlers left to use after that. But AddHandler
had the problem described earlier.

So this is not yet the complete solution. To repeat the goal:
      * I want to hide mymodule.py in the URI.
      * I want requests to be handled by a handler function in
      * I want to be able to use the specified path as a parameter
        (req.path_info) to the handler function.
      * When the path matches a directory, I want the contents of that
        directory to be displayed (either by normal processing or by
        another python module located in that directory).

Using the publisher handler works, as Grisha suggested. I'll summarize
it below for reference.

SetHandler mod_python
PythonHandler mod_python.publisher

def index (req):
  return "We are in index()\npath_info: "+ repr(req.path_info)

Any directory will then be assumed to contain an index.py with a
function named index(). If that is not desired, it can be turned off by
placing a .htaccess file in that directory saying "SetHandler None".
Normal processing will then apply to that directory. Other functions can
be called by naming them in the URI, and they can be given "parameters"
by appending them to the URI. This way, the user will never know the
difference between a "real" directory and output produced by a python

So, having that sorted out I can proceed with my experiments. Thanks for
the suggestions! :)

Fabian Fagerholm <fabbe at paniq.net>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://modpython.org/pipermail/mod_python/attachments/20040512/a21f028d/attachment.bin

More information about the Mod_python mailing list