[mod_python] newbie question

Nic Ferrier nferrier at tapsellferrier.co.uk
Wed Oct 27 15:10:51 EDT 2004


"Golawala, Moiz M \(GE Infrastructure\)" <Moiz.Golawala at ge.com> writes:

> Hi All, 
> 
> I guess, I didn't really describe what my problem was so I will
> include some code snippets to explain what I am confused about.
> 
> In my httpd.conf file:
> <Directory /var/www/html/>
> 	PythonHandler main
> 	PythonDebug on
> </Directory>
> 
> in my main.py file:
> 
> from cheetah.Template import Template
> from mod_python import apache
> 
> def handler(req):
> 	t = Template(file,"/var/www/html/main.tmpl")
> 	textlen = len(str(t))
> 	req.set_content(t)
> 	req.set_content_length(textlen)
> 	apache.OK	
> 
> in my main.tmpl file:
> 
> <html>
> <head></head>
> <body>
> 	<form action="valid.py">
> 	<input type="text" size="20" name="input1">
> 	<input type="text" size="20" name="input2">
> 	<input type="submit" name="submit" value="submit">
> 	</form
> </body>
> </html>
> 
> My problem is that the browser renders the page that is defined in
> the main.tmpl file. But once I enter the text and click submit. I
> want the browser to display the page that is defined the template
> used in valid.py (as the form tag shows) but some how I get the
> main.py page back. The reason this is happening is that once I click
> the submit button, I get back to the server and the handler is
> invoked and main.py is called. I can never go to another page.
> 
> I am sure I am doing something wrong. Please can someone help me
> out.. Or direct me to some place that show an example of how this
> mechanism works correctly.

The reason is that the request is being received by Apache and it is
consulting it's config file to see what it should do, this:

> <Directory /var/www/html/>
> 	PythonHandler main
> 	PythonDebug on
> </Directory>

The PythonHandler statement tells Apache to pass all requests to the
main.py handler so your valid.py doesn't get a look in.

Adding this to your config would be a quick fix:

  <Location /valid.py>
    SetHandler python-program
    PythonHandler valid
  </Location>

But consult the documentation for mod_python and the various handler
tools to establish alternatives that may suit you better.

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk


More information about the Mod_python mailing list