Python Forms?

Max M maxm at mxm.dk
Thu Oct 10 13:46:49 EDT 2002


Nico C. Kalteis wrote:


> First of all, thank you to anybody who can answer me this.  I'm primarily an
> ASP developer and have only recently had cause to tinker with Python.  So
> here is my question:
> 
> Is there a way to use Python to retrieve variables that are passed to it by
> a form without using a CGI script?  In other words, is there something
> equivalent to the ASP script:
> 
> <% localvariable = request("querystring") %>


You can use the attached module and use the request function to get a 
dict with the values from the windows Request object:

#    from iisUtils import request
#    req = request(Request) # pass the iis Request object as parameter
#
#    # getting simple value
#    value = req['value']
#    Response.Write('%s<br>' % value)
#
#    # getting list of values (values with same name makes a list)
#    values = req['values]
#    for value in values:
#        Response.Write('%s<br>' % value)
#
#    # Checking for checkbox value
#    # (checkboxes only gets passed if they are checked)
#    checkValue = req.has_key('checkValue')
#    if checkValue:
#        "Do stuff"
#
#    # Getting value with default value if non-existing key.
#    checkValue = int(req.get('checkValue', 'unchecked'))
#    if checkValue == 'checked':


There is also a winFieldStorage function that makes it possible to use 
the FieldStorage object from the standard cgi module. This makes it easy 
to do file uploads.


regards Max M

 ><evolve>
   >    >
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: iisUtils.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20021010/d1d46c05/attachment.ksh>


More information about the Python-list mailing list