Using CGI module with 'canned queries'

Paul Boddie paulb at infercor.no
Wed Apr 19 06:36:38 EDT 2000


Lars von Wedel wrote:
> 
> Hello,
> 
> I want to use Python to implement some CGI scripts. I want these
> scripts to be callable from any link (not only via a form),
> e.g. the user shall be able to enter something like
> 
> http://.../test.py?name=Bill
> 
> into Netscape directly.

The parameter(s) should still be received correctly in the CGI script.

> I expected that such a URL could be processed using
> 
>     form = cgi.FieldStorage()    print '<UL>'
>     for k in form.keys:
>         print '<LI>' % k % ':' % form[k] % '</LI>'

Surely you mean...

          print '<LI>' + k + ':' + form[k].value + '</LI>'

> (after printing an html header of course).
> 
> However, the dictionary seems to be empty when the http daemon
> starts my script.

Are you sure that the problem doesn't lie in the fact that form[k] is not likely
to be a string, but a FieldStorage object instead? Thus, you must refer to the
value attribute of form[k].

> How do I access parameters within the script if not started via a form?

You should be able to do just that with the 'cgi' module.

Paul



More information about the Python-list mailing list