[mod_python] Unable to import modules in subdirs

Graham Dumpleton grahamd at dscpl.com.au
Thu Oct 27 18:55:25 EDT 2005

Jorey Bump wrote ..
> Brandon N wrote:
> > A) Is it requestHandler's job to determine which file was requested and
> > respond accordingly (via the request's .filename?) with a switch 
> > construct or equivalent?
> Yes and no. Apache's already passed the file to the handler based on its
> extension, presence in a directory, or other criteria. The developer of
> the handler gets to decide what the handler does with *whatever* is 
> passed to it. Some assume it will contain only valid Python code and 
> process it as such (mod_python.publisher, for example). Some might want
> to process proprietary or other file formats using python (you might 
> make a handler to display Word files, for example), but remain agnostic
> about the actual filename or extension. But there's no reason why your
> handler can't branch according to the file extension (which is what 
> Graham's Vampire does, if I'm not mistaken).

If you are coming from a PHP background where each URL essentially
maps to a distinct file, Vampire may well be a good starting point as it
works in a similar way at it most basic level.

Thus, where in PHP you might have:

  index.php # URL -> /index.php
  search.php # URL -> /search.php

Vampire would similarly have separate files for each resource, although
in Vampire it is the name of the handler within the file which dictates
what extension the URL needs to have:


    def handler(req): ... # /index
    def handler_html(req): ... # /index.html
    def handler_php(req): ... # /index.php (Yes, pretend we are PHP when we aren't).


    def handler(req): ... # /search
    def handler_html(req): ... # /search.html

Thus, if you want to write your code in the form of basic handlers but a
distinct handler for each resource, the basic dispatch mechanism of
Vampire is going to allow you to get started quicker.

Another alternative as Jorey pointed out is mod_python.publisher,
however it doesn't allow you to as easily dictate use of multiple
different extension types used on URLs nor is it necessarily as easy to
mix static files in the same directory.

For a further basic introduction to Vampire, see:



More information about the Mod_python mailing list