[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
		Page=1
	elif req.unparsed.uri == "/page2.html":
	      #Do something for page2
		Page=2
	Send_page(req,Page)
	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

Martijn

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


  
_______________________________________________
Mod_python mailing list
Mod_python at modpython.org
http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list