CGI docs

Mark Sienkiewicz sienkiew at
Fri Oct 25 15:52:29 CEST 2002

>I want to send parameters to my CGI programmes in the URL, not in any html
>form. I am looking for a way to read in the parameters from the URL.
>For example, I have the following link in a webpage:
><a href = "http://localhost/mhpp/'Catalin'">name</a>
>I want my script "" to be able to pick up the
>"name:Catalin" pair. 

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

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

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

More information about the Python-list mailing list