Output a HTML page : HTML « CGI Web « Python Tutorial






#!/usr/local/bin/python
import cgi

def header(title):
    print "Content-type: text/html\n"
    print "<HTML><HEAD><TITLE>%s</TITLE></HEAD><BODY>" % (title)

def footer():
    print "</BODY></HTML>"

form = cgi.FieldStorage()
formkeys = form.keys()
formkeys.sort()
header("Show form fields")

print '<UL>'
for k in formkeys:
    print '<LI>' + k + ':' + form[k].value + '</LI>'
print '</UL>'

footer()








22.2.HTML
22.2.1.Output html tags
22.2.2.Output
22.2.3.Output a HTML page