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

Vicki Stanfield vicki at stanfield.net
Tue Mar 22 15:02:17 CET 2005

I have recently started doing cgi in Python and have run into a problem. I
have an html form which has various widgets which accept data. I also have
this in that html file:

<form action="formdata.py" method="post">

formdata.py runs but doesn't seem to contain the data from the form. I'm
not sure of the format for the for with regard to FieldStorage btw. Here
is the contents of formdata.py:

#! /usr/bin/python
import cgitb, os, sys

import cgi

print "Content-Type: text/html\n\n"
print "<html><head></head><body>"
form = cgi.FieldStorage()
for each in form:
        print "each"
print form['fname'].value, form['lname'].value
#print "address:", form['addr'].value()
print "</body></html>"

More information about the Tutor mailing list