2014-05-16 + HW

posted May 16, 2014, 5:44 AM by Samuel Konstantinovich   [ updated May 16, 2014, 4:27 PM ]
Goal: Processing form data.

1. After you send form data to a website like this:
    localhost:9000/cgi-bin/mypyfile.py?x=3&y=2&mode=maths&output=eng


we can retrieve the variable names and their values in python using cgi: (the following should be mypyfile.py)

#!/usr/bin/python
print 'Content-type: text/html\n\n'
import cgi
form=cgi.FieldStorage() #this gets all the variables in a dictionary

if len(form)>0:
        for key in form: #just like a dictionary
            value=form[key].value #this is an extra step
            print key+','+value+'<br>'



Homework:
1. Remember to finish your data analysis project.
2. Lab18
Make form.py  and process.py  such that:
form.py is a website that has a form that is linked to process.py.
process.py is a website that not only displays the information but does different things when you use the checkboxes or radio buttons. 
Comments