cgi.FieldStorage and POST
Jeff Hinrichs
jlh at home.com
Wed Jan 2 18:50:25 EST 2002
Max,
Here is the info you requested and some more just in case you need.
Thanks,
Jeff
Here is the form:
------------------
<html>
<head><title> Module Upload</title></head>
<body>
<form name="upload" method="POST">
<input type="hidden" name="a" value="b">
<input type="text" name="c" value="d">
<input type="submit" name="cmdUpload" value="send">
crap
</form>
</body>
</html>
Here is my server:
------------------
from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler
import os
print "Starting Python Web Server..."
port = 999
servr = HTTPServer(('', port), CGIHTTPRequestHandler)
servr.serve_forever()
and here is my cgi:
---------------------
# Actually on CGI is required, but sys allows us to redirect stderr
import cgi,sys
#make sure errors go to standard out, first thing to do in script
sys.stderr = sys.stdout
print 'Content-type: text/html\n'
def printFormVars(fields):
for key in fields.keys():
print key, "=>",fields[key].value, '<br>'
#def getValue(fields,key):
# return pipes.quote(fields[key].value)
form = cgi.FieldStorage()
#print form.keys()
if not form:
#display blank form
print '<html>'
print '<head><title> Module Upload</title></head>'
print '<body>'
print '<form name="upload" method="POST">'
print '<input type="hidden" name="a" value="b">'
print '<input type="text" name="c" value="d">'
print '<input type="submit" name="cmdUpload" value="send">'
print 'crap'
print '</form>'
print '</body>'
print '</html>'
else :
#perform action
#REMEMBER TO SANITIZE INPUT i.e. user = pipes.quote(form"user"].value)
print '<html>'
print '<head><title> Module Upload</title></head>'
print '<body>'
printFormVars(form)
print '</body>'
print '</html>'
> ----- Original Message -----
> From: "maxm" <maxm at mxm.dk>
> To: "Jeff Hinrichs" <jlh at home.com>
> Sent: Wednesday, January 02, 2002 3:00 AM
> Subject: Re: cgi.FieldStorage and POST
>
>
> > We really need to see the form also.
> >
> > If ie. you are uploading a file, you need to set
> > enctype="multipart/form-data". Which is easy to forget.
> >
> > regards Max M
> >
> > "Jeff Hinrichs" <jlh at home.com> wrote in message
> > news:mailman.1009948862.8390.python-list at python.org...
> > > I'm playing with python's cgi module and I am encountering an
unexpected
> > > problem.
> >
> >
> >
> >
> >
>
More information about the Python-list
mailing list