home *** CD-ROM | disk | FTP | other *** search
- <TITLE>Introduction to the CGI module -- Python library reference</TITLE>
- Next: <A HREF="../u/using_the_cgi_module" TYPE="Next">Using the cgi module</A>
- Prev: <A HREF="../c/cgi" TYPE="Prev">cgi</A>
- Up: <A HREF="../c/cgi" TYPE="Up">cgi</A>
- Top: <A HREF="../t/top" TYPE="Top">Top</A>
- <H2>10.1.1. Introduction</H2>
- A CGI script is invoked by an HTTP server, usually to process user
- input submitted through an HTML <CODE><FORM></CODE> or <CODE><ISINPUT></CODE> element.
- <P>
- Most often, CGI scripts live in the server's special <CODE>cgi-bin</CODE>
- directory. The HTTP server places all sorts of information about the
- request (such as the client's hostname, the requested URL, the query
- string, and lots of other goodies) in the script's shell environment,
- executes the script, and sends the script's output back to the client.
- <P>
- The script's input is connected to the client too, and sometimes the
- form data is read this way; at other times the form data is passed via
- the ``query string'' part of the URL. This module (<CODE>cgi.py</CODE>) is intended
- to take care of the different cases and provide a simpler interface to
- the Python script. It also provides a number of utilities that help
- in debugging scripts, and the latest addition is support for file
- uploads from a form (if your browser supports it -- Grail 0.3 and
- Netscape 2.0 do).
- <P>
- The output of a CGI script should consist of two sections, separated
- by a blank line. The first section contains a number of headers,
- telling the client what kind of data is following. Python code to
- generate a minimal header section looks like this:
- <P>
- <UL COMPACT><CODE> print "Content-type: text/html" # HTML is following<P>
- print # blank line, end of headers<P>
- </CODE></UL>
- The second section is usually HTML, which allows the client software
- to display nicely formatted text with header, in-line images, etc.
- Here's Python code that prints a simple piece of HTML:
- <P>
- <UL COMPACT><CODE> print "<TITLE>CGI script output</TITLE>"<P>
- print "<H1>This is my first CGI script</H1>"<P>
- print "Hello, world!"<P>
- </CODE></UL>
- (It may not be fully legal HTML according to the letter of the
- standard, but any browser will understand it.)
- <P>
-