[mod_python] Unable to import modules in subdirs

Jorey Bump list at joreybump.com
Thu Oct 27 17:44:22 EDT 2005

Brandon N wrote:
> Thanks a lot, that helped considerably. I'm not sure why but from an 
> example I had come across I though mod_python handled things a little 
> differently than I was used to.
> One last (multi-part) question. I'm going to be using some php for a 
> while, so I've specified /py as the directory to point python requests to.
> 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).

> B) How does one route /py/*/ etc requests to the same handler? Or should 
> one register a handler for each particular subdirectory?

The (Set|Add)Handler directive is recursive, you only need to set it at 
the topmost directory. Apache will route the files in subdirectories 
through the same handler. Multiple (Set|Add)Handler directives are 
allowed, if you want to add other directories. I'll often set up 
multiple directories outside of the DocumentRoot and alias them, 
especially if I'm sharing the host with nonprogrammers who update HTML only.

More information about the Mod_python mailing list