Use of HTMLgen

CGI script continued:
form = cgi.FieldStorage()
if form.has_key("r"):  
    r = form.getvalue("r"); s = math.sin(float(r))
else:
    r = "1.2"; s = math.sin(float(r))  # default

# use HTMLgen to generate the Web document:
doc = SimpleDocument(title='Hello, Web World!', 
                     bgcolor=WHITE, cgi=1)
# make form, give URL of the CGI script to call:
F = Form('hw3.py.cgi') 
F.append(Input(type='TEXT', # one-line text
     name='r', size=10, value=r, 
     # label to the left of the text field:
     llabel='Hello, World! The sine of ',
     # label to the right of the text field:
     rlabel=" is %g" % s))
# submit button:
F.submit = Input(type='submit', value='compute') 
doc.append(F)
doc.write()

previousnexttable of contents