Abstract
Describes the techniques for generating Web pages dynamically, especially from the XHTML forms interface.
This publication is available in Web form and also as a PDF document. Please
forward any comments to tcc-doc@nmt.edu.
Table of Contents
anyform.cgi: An example CGI script to show
all form datareader.cgi: An example script
with cookiesreader.cgi: Prologuemain(): Main programdeleteCase(): Delete the cookiedeletionPage(): Generate the
deletion-successful pagegenericPage(): Build a generic Web
pagechapterCase(): Present the next
chapterupdateDatabase(): Update or create
the user's database entrynewUserRecord(): Create the initial
user recordsetCookie(): Set a cookiegenerateChapter(): HTML page
generationgenerateForm(): Build the form elementnavButtons: Add navigational buttonsradioGroup(): Add the radiobutton
groupclass Inputs: All the script's inputInputs.__init__(): Constructorclass UserDatabaseUserDatabase.__init__(): ConstructorUserDatabase.__getitem__(): Implement
dictionary getUserDatabase.__setitem__()UserDatabase.__delitem__()UserDatabase.cleanup()UserDatabase.close()class UserRecord
Most Web pages are static: the
same content appears each time you visit that URL. To put
up static content, you simply place a file in or under a
specific directory, and give it a name that ends in
“.html”. If your page is
hosted at the New Mexico Tech Computer Center (TCC), static
pages must reside in subdirectory “public_html” under your home directory.
This document describes technique for dynamic web pages: their content is generated on demand. This technique is called CGI, for Common Gateway Interface. Instead of writing the page's content, you will write a program that generates the content as its output. Such a program is called a CGI script (nowadays the terms “script” and “program” are pretty much interchangeable). The program can be written in just about any modern programming language. We'll describe how to do it in the Python language, a very good modern general-purpose programming language.
One of the commonest uses for dynamic web pages is to handle forms. For example, you might put up a web page displaying a form that allows the user to enter search terms for a database query. When they click on the button, a new page appears that displays the results of their query.
However, dynamic web pages are useful for other applications besides forms handling. For example, you might put up a “Site Map” link that takes the user to an interactive site map. An example is the site map for the TCC Help System.