CGI docs

Doru-Catalin Togea doru-cat at ifi.uio.no
Fri Oct 25 11:43:32 EDT 2002


> Maybe you are missing some of the background on how CGI works.

Yes, my testing script fooled me (that is I fooled myself), as I called it
by clicking on a button in a form. I could read the values of the form's
fields, but not the values given in the actions field of the button.

That is, I had the following "action" specification for my form:

<form method = "post" action =
"http://localhost/mhpp/hello.py?name='Catalin'">

and I expected my script to see the "name='Catalin'" pair when clicking 
the submit button. It didn't while I could read in the other fileds of the
form so I figured I had to use another approach then

	f = cgi.FieldStorage()
	...

I did some more reading, and I can now get the parameters from both the
action specification or from the URL.

Thanks everyone for help.

Catalin

> 
> CGI has two ways of passing parameters in: GET and POST.  If the form
> uses POST, your cgi program sees the parameters on standard input.  The
> details of how that happens are not important - the web server handles
> it.
> 
> If the form uses GET, the browser constructs a URL that looks exactly
> like the one you used in your example.  The parameters come to your
> CGI program as environment variables.  
> 
> The library recognizes whether the browser used GET or POST to send
> the data, and does the right thing.  Because you wrote the URL that
> way, it thinks the browser used GET.  You can handle the data in the
> same way as you would handle form data.
> 
> The interesting documentation is in "Python Library Reference" section
> 11.2.  Just pretend your input is form data.  From looking over the
> documentation, I think the interface in section 11.2.3 is a little
> easier to use.  For most reasonable CGI programs, you would use
> 	import cgi
> 	f = cgi.FieldStorage()
> 	name = f.getfirst("name")
> 	otherthing = f.getfirst("otherthing")  # if you have another parameter
> 
> 
> 



	<<<< ================================== >>>>
	<<     We are what we repeatedly do.      >>
	<<  Excellence, therefore, is not an act  >>
	<<             but a habit.               >>
	<<<< ================================== >>>>





More information about the Python-list mailing list