Question using CGI in Python

Chris Dutton chris at cmb-enterprises.com
Tue Aug 28 23:45:48 EDT 2001


in article mailman.999027702.15146.python-list at python.org, Shane Anglin at
shane.anglin at mtni.net wrote on 8/28/01 3:39 PM:

> Non-working example:
> --app1.py:
> print "<FORM METHOD='POST' ACTION='app2.py'>
> print '<input type="text" size="10" name="var1">'
> print "<P><INPUT type='submit' value='Submit'></P>"
> </FORM>
> #SUBMIT
> 
> --app2.py:
> form = cgi.FieldStorage()
> VAR1 = form["var1"].value

At least using Python 2.0 on a FreeBSD webserver, this could possibly raise
an exception.

instead use

try: 
   VAR1 = form['var1'].value
except: 
   VAR1 = ''

if the person submitting the form leaves the "var1" textfield blank,
cgi.FieldStorage() won't know form['var1'].value exists.

As for the rest... """ is your friend.




More information about the Python-list mailing list