[mod_python] newbie question - using multiple handlers

Graham Dumpleton grahamd at dscpl.com.au
Tue Jul 25 18:11:51 EDT 2006


Thomas J. Schirripa wrote ..
> I'm pretty new to both mod_python and apache. I have just written multiple
> handlers to deal with different webpages I have written. My problem is
> that if I use PythonHandler for each of my handlers in the conf. file,
> whenever I run a webpage, it tries to use ALL my handlers. Basically, I
> want only one handler to be used per webpage. The "action" in my forms
> only specify one handler, but based on the errors I am getting, it is also
> running the other handlers. Is there a way that I can set directives such
> as PythonHandler for particular html files? Or do I need to separate my
> files into different directories? I would hate to have to make a switch
> handler that determined what methods to call from my handler files so that
> the conf file only had one handler in it.

Post what Apache configuration you are using for your PythonHandler
and SetHandler/AddHandler directives related to mod_python. Is this
being set in a .htaccess file or in main Apache configuration within a
Directory/Location directive?

If the PythonHandler directives at present refer sto your own handlers, use
of a switch or dispatch handler may be your only choice when using mod_python
3.2.X or earlier versions. This is because the logical thing to do of:

  <Files page1.html>
  PythonHandler handlers::page1_html
  </Files>

  <Files page2.html>
  PythonHandler handlers::page2_html
  </Files>

doesn't necessarily work, although it is fixed in development version of
mod_python 3.3.

The problem with using <Files> is that mod_python sets up Python path
wrongly and if handlers.py is in the directory for the .htaccess or Directory
directive it will not find it. Will be okay if handler.py is elsewhere and the
PythonPath directive is used to refer to the directory where it is located.

Rather than try and hack up a solution you may want to look at Vampire
which already provides a basic switch or dispatch handler which maps
to basic mod_python handlers. This way you can have separate handler
files for each resource and if necessary distinct handlers for different
views of a resource as well. See:

  http://www.dscpl.com.au/projects/vampire/articles/vampire-001.html

for a quick overview of Vampire.

Graham


  


More information about the Mod_python mailing list