CGI passes information to Python in the form of a class called FieldStorage. In your Pythonic CGI script, you must create an instance of FieldStorage in order to access the CGI data. The main attribute of class FieldStorage which you will need to know is 'getvalue'. For example, the data from an address book form might be accessed as follows:
# Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from field 'name' name = form.getvalue('name') # Get data from field 'address' address = form.getvalue('address') # Get data from field 'phone' phone = form.getvalue('phone') # Get data from field 'email' email = form.getvalue('email')
From here, the data has been assigned to the variables. You can thus handle the values within the program like other literals.