[mod_python] mptest.py works, other .py files don't

Graham Dumpleton grahamd at dscpl.com.au
Wed Jan 19 19:45:21 EST 2005


Bas van Dorp wrote ..
> I don't get it. I would like to tell Apache to parse all .py scripts in
> certain directories, just like I do with .php scripts. But how?

The closest analogy to that will be what is supported by Vampire.

  http://www.dscpl.com.au/projects/vampire

Your config would be:

  SetHandler mod_python
  PythonHandler vampire
  PythonDebug On

You can then stick any type of file, eg. .html, .jpg etc, into the directory
or any subdirectories. Those files will be served up normally.

At the same time, if you have .py files, they can potentially intercept a
request for a resource with the same basename. For example, if a request
is for "foo.html" and you have a Python file "foo.py", if the Python file
defines "handler_html()", then that method will be called to generate
the response. Note that "foo.html" didn't have to exist in doing that,
ie., could be purely generated content. Alternatively, if could read in
a physical "foo.html" and modify it in some way and return it. Ie., fill
out template data.

Unlike with mod_python.publisher where the methods for different
resources are generally all in the one code file, when using Vampire
each Python file relates to a specific resource. There can be multiple
methods in a Python file in Vampire, but this is only done when a
resource can be represented in multiple formats.

Also, in Vampire, the methods are basically standard mod_python
content handlers whereas with mod_python.publisher, how data and
status is returned is different.

Have fun.

Graham


More information about the Mod_python mailing list