[mod_python] newbie question - using multiple handlers

Martijn Moeling martijn at xs4us.nu
Tue Jul 25 20:49:43 EDT 2006

I would do it different

I would do something like this:

One handler in the apache config

Def handler(req):
	If req.unparsed_uri == "/page1.html":
		#Do something for page1
	elif req.unparsed.uri == "/page2.html":
	      #Do something for page2
	Return Apache.Ok

Def Send_page(req,Page):
	req.write("this is page : "+str(Page))

(My outlook messes up the use of small and capital letters, you get the
point though


-----Oorspronkelijk bericht-----
Van: mod_python-bounces at modpython.org
[mailto:mod_python-bounces at modpython.org] Namens Graham Dumpleton
Verzonden: Wednesday, July 26, 2006 00:12
Aan: Thomas J. Schirripa
CC: mod_python at modpython.org
Onderwerp: Re: [mod_python] newbie question - using multiple handlers

Thomas J. Schirripa wrote ..
> I'm pretty new to both mod_python and apache. I have just written
> 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,
> 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
> running the other handlers. Is there a way that I can set directives
> as PythonHandler for particular html files? Or do I need to separate
> files into different directories? I would hate to have to make a
> handler that determined what methods to call from my handler files so
> 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,
of a switch or dispatch handler may be your only choice when using
3.2.X or earlier versions. This is because the logical thing to do of:

  <Files page1.html>
  PythonHandler handlers::page1_html

  <Files page2.html>
  PythonHandler handlers::page2_html

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
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

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:


for a quick overview of Vampire.


Mod_python mailing list
Mod_python at modpython.org

More information about the Mod_python mailing list