CGI: How do I do this?

Bryan L. Fordham bfordham at socialistsushi.com
Fri Oct 25 08:17:48 EDT 2002


Doru-Catalin Togea wrote:
[snip]
> print header(), start_html();
> my @fields = CGI::param();                 <-- how do I do this
>                                                in Python?
> print "<pre><br>\n";
> foreach my $k (@fields) {
>     my $v = param($k);
>     print "<b>$k</b> -> \"$v\"<br>";
> }
[snip]

from http://www.python.org/doc/current/lib/node297.html --

 > form = cgi.FieldStorage()
 > if not (form.has_key("name") and form.has_key("addr")):
 >     print "<H1>Error</H1>"
 >     print "Please fill in the name and addr fields."
 >     return
 > print "<p>name:", form["name"].value
 > print "<p>addr:", form["addr"].value
 > ...further form processing here...

You can also do form.keys()

The cgi module docs are pretty helpful; poking around in there should 
show you everything you want to know 8)

--B






More information about the Python-list mailing list