[Tutor] Python cgi doesn't get data from html form as expected

Vicki Stanfield vicki at stanfield.net
Tue Mar 22 16:33:40 CET 2005


> I haven't done too much web stuff (or much of anything) with python, but
> I looked into your question a bit (researching other's problems may help
> me avoid them =)).  A quick search brought up this page which seems to
> have information which may help you.
>
> http://gnosis.cx/publish/programming/feature_5min_python.html
>
> Hope that helps.
> Best Regards,
> Michael Lasky

I don't see anything in that page that changes what I am doing. I can get
rid of everything that has to do with retrieving data from
cgi-FieldStorage, and the code executes fine although I get a blank page.
I have revised the code somewhat, but the initial problem of
cgi.FieldStorage being empty is still there. I don't get an error now,
just an empty page. Here is the revised code:

 #! /usr/bin/python
print "Content-Type: text/html\n\n"
print
print "<html><head></head><body>\n\n"

import cgitb, os, sys
cgitb.enable()
sys.strerr = sys.stdout

import cgi

form = cgi.FieldStorage()
field_list = '<ul>\n'
for field in form.keys():
    field_list = field_list + '<li>%s</li>\n' % field
field_list = field_list + '</ul>\n'
print field_list
print "</body></html>\n\n"



More information about the Tutor mailing list