mod_python newbie question.

Steve Holden steve at holdenweb.com
Thu Oct 28 10:37:05 EDT 2004


Golawala, Moiz M (GE Infrastructure) wrote:

 > Thank you so much for the in detail explanation that you provided me. 
I tried what you said and it works wonderfully.
 >
Moiz:

It's a pleasure: in future if you reply via the list I'll normally see 
it, and then so will others in case it's a follow up, but I am glad to 
have been of assistance. I am taking the liberty of copying this reply 
to the Python list, I hope you don't mind.

 > So I should have a main.py that defines all the functions that point 
to different pages (more like pages I have to navigate to) the publisher 
handler will take me there by appending what is in the FORM action tag 
to the URL.
 >
In actual fact there is no *requirement* for all pages to be a part of 
the same Python file, that's just a convenience feature which makes it 
easy for the different pages to share code. The benefit mod_python gives 
is that once a module is loaded it stays resident in the Python 
interpreter embedded within the Apache process, so you incur less 
overhead. As another poster pointed out, this can also be a source of 
difficulty at times - although changes to the page module will be 
automatically detected and a reload() executed as required, if your 
module imports *other* modules then changes to those modules won't be 
automatically handled. This seems a fair compromise to me, but others 
dislike it (I normally add a "refresh" function to allow me to manually 
reload all imported modules during testing).

As far as the form contents being appended to the URL goes, this is a 
consequence of your form using the default GET method. If you added a

	method="POST"

attribute to your <form> tag the browser would then transmit the form 
contents as the body of the HTTP request. This would then make them 
available as the contents of a FieldStorage object *as well* as putting 
any that match your page function's argument names being included in the 
argument list. This is explained, though rather tersely, in

http://www.modpython.org/live/current/doc-html/hand-pub-alg-args.html

and

http://www.modpython.org/live/current/doc-html/hand-pub-alg-args.html

 > Since I am a newbie.. anything that works gets me excited. But please 
would you tell me is this how page navigation is accomplished in a 
professional page as well. This is the way to work with mod_python or is 
it a newbie way to work with mod_python.. :)
 >
I think most mod_python users use the publisher handler. I have written 
handlers myself, but Grisha told me I was abusing the request handler 
for the purposes I wanted to satisfy, and to use a fixup handler, so 
clearly I'm no expert. If you've got the sample fully working it might 
be an idea to submit it to see if it could be used as a sample in the 
documentation somewhere.

The world of the web is still pretty much a "do what works" community, 
but the techniques we have discussed will take you a long way.

Note, however, that it will be a good idea to get a better understanding 
of the underlying operation of the web (in terms of HTTP interactions) 
to better understand how to structure your sites, and what's going on 
under the hood.

You can do a lot without mod_python just by writing CGI scripts (in 
Python, naturally ;-) but no matter what's at either end of the link, in 
a web system they will be using HTTP to communicate.

regards
  Steve

[Sorry about the quoting, Mozilla crashed during the first send]
-- 
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119




More information about the Python-list mailing list