Output html list : Introduction « CGI Web « Python Tutorial






#!/usr/bin/env python

import cgitb
cgitb.enable()

import cgi, os, urllib

print "Content-type: text/html"
print

print """<HTML>
<HEAD>
<TITLE>CGI List Example</TITLE></HEAD><BODY>"""

form = cgi.FieldStorage()
print "You selected: "
selections = form.getlist('data')
printable = [cgi.escape(x) for x in selections]
print ", ".join(printable)


print """<FORM METHOD="GET" ACTION="%s">
Select some things:<P>""" % os.environ['SCRIPT_NAME']
for item in ['A', 'B', 'C', 'D', 'E', 'F','G']:
    print '<INPUT TYPE="checkbox" NAME="data" VALUE="%s">' % cgi.escape(item)
    print ' %s<BR>' % cgi.escape(item)
print """<INPUT TYPE="submit" NAME="submit" VALUE="Submit">
</FORM>
</BODY></HTML>"""








22.1.Introduction
22.1.1.A Simple CGI Script
22.1.2.CGI Environment
22.1.3.A Script for Displaying the Environment
22.1.4.Your First Python CGI Script: Hello Apache
22.1.5.Programming Web Services
22.1.6.Processing Parameters Passed to CGI Scripts
22.1.7.Displays the current date and time in a Web browser.
22.1.8.Program to display CGI environment variables
22.1.9.Output current time
22.1.10.escape strings
22.1.11.Output html list
22.1.12.print web page content