#!/usr/bin/python2 import cgi def main(): form = cgi.FieldStorage() # standard cgi script lines to here! # use format of next two lines with YOUR names and default data xStr = form.getfirst("x", "0") # get the form value associated with form # name 'x'. Use default "0" if there is none. yStr = form.getfirst("y", "0") # similarly for name 'y' # do YOUR thing - manipulate the data, and create results x = int(xStr) y = int(yStr) sum = x+y sumStr = str(sum) # output by embedding into YOUR separate format page YOUR results showPage("adderAnswer.html", (xStr, yStr, sumStr) ) # note tuple paramater def showPage(templateFileName, substitutions): # keep this handy function """ templateFileName is the string name of the html file used as a format string. substitutions is either a single data item or an explicit tuple containing the data to substitute into the format string in the file. The function prints the string created from the file's format string and the supplied substitutions. """ fin = open(templateFileName); #page could be a canned string page = fin.read(); # in the program but this allows the visual display fin.close() # to be changed separately from the logic. print page % substitutions #standard lines from here on try: print "Content-type: text/html\n\n" # say generating html main() except: cgi.print_exception() # catch and print errors