[mod_python] Execution Order of Handlers & MVC in mod_python

Alexis Marrero-Narváez amarrero at mitre.org
Wed Dec 1 20:33:58 EST 2004

I need enlightenment with this subject. I have the following 
Alias /python/ "/Users/amarre/Sites/web-app/"
<Directory "/Users/amarre/Sites/web-app/">
     AddHandler mod_python .py
     PythonHandler hello
     AddHandler mod_python .psp
     PythonHandler mod_python.psp
     PythonDebug On

In my /Users/amarre/Sites/web-app/ I have two files hello.py and 
hello_a.psp. If I visit the url http://localhost/python/hello_a.psp I 
display the ouput of hello.py concatenated with the output of 
hello_a.psp. This tells me that one (hello.py) was executed before the 
other one (hello_a.psp).
  I understand that if I define more than one handle they executed in 
the order they are added but, the first handler was added for ".py" 
files and the second one for ".psp". And that's what is confusing me.

How can I change the configuration to have both files coexist in the 
same directory while executing just the one being addressed by the URL?

The next question is regarding how to implement the MVC pattern. How 
does this two options compare:

Combining mod_python.publisher with PSP templates vs. mod_python 
generic handler and mod_python.psp handler. By the second I mean doing 
all the business logic in the generic handler and using the req object 
as a container of anything that needs to be passed on to the psp. For 

def handler(req):
	#do all logic
	#now add any data to the req object
	req.name = 'name'
	req.greeting = 'hello'
	return apache.OK

Then in the psp, we can use req.name and req.greeting as we please. To 
be more fancy I could create a Container object that I then put it in 
the request object for later use in the PSP.

One of the disadvantages that I see by implementing by using publisher 
+ psp is that you don't have the great power of doing 
http://example.com/mypsp.psp_ (underscore for debbuging).

How does this two options compare and why should I go for one rather 
than the other?

The last question is (related to the first one), how can I configure 
httpd.conf so I could have multiple python scripts in the same 
directory and be able to address them separately. For instance:

Access each one independently of the other one.

I hope that anyone can understand all this!


More information about the Mod_python mailing list