Internet addresses (URLs)
Once you write an HTML file, you need to put it somewhere a web browser can ref-
erence it. If you are using the locally running Python web server described earlier, this
becomes trivial: use a URL of the form http://localhost/file.html to access web pages,
and http://localhost/cgi-bin/file.py to name CGI scripts. This is implied by the fact that
the web server script by default serves pages and scripts from the directory in which it
is run.
On other servers, URLs may be more complex. Like all HTML files, tutor0.html must
be stored in a directory on the server machine, from which the resident web server
program allows browsers to fetch pages. For example, on the server used for the second
edition of this book, the page’s file must be stored in or below the public_html directory
of my personal home directory—that is, somewhere in the directory tree rooted
at /home/lutz/public_html. The complete Unix pathname of this file on the server is:
/home/lutz/public_html/tutor0.html
This path is different from its PP4E\Internet\Web location in the book’s examples dis-
tribution, as given in the example file listing’s title. When referencing this file on the
client, though, you must specify its Internet address, sometimes called a URL, instead
of a directory path name. The following URL was used to load the remote page from
the server:
http://starship.python.net/~lutz/tutor0.html
The remote server maps this URL to the Unix pathname automatically, in much the
same way that the http://localhost resolves to the examples directory containing the web
server script for our locally-running server. In general, URL strings like the one just
listed are composed as the concatenation of multiple parts:
Protocol name: http
The protocol part of this URL tells the browser to communicate with the HTTP
(i.e., web) server program on the server machine, using the HTTP message proto-
col. URLs used in browsers can also name different protocols—for example,
ftp:// to reference a file managed by the FTP protocol and server, file:// to reference
a file on the local machine, telnet to start a Telnet client session, and so on.
Server machine name and port: starship.python.net
A URL also names the target server machine’s domain name or Internet Protocol
(IP) address following the protocol type. Here, we list the domain name of the
server machine where the examples are installed; the machine name listed is used
to open a socket to talk to the server. As usual, a machine name of localhost (or the
equivalent IP address 127.0.0.1) here means the server is running on the same
machine as the client.
Optionally, this part of the URL may also explicitly give the socket port on which
the server is listening for connections, following a colon (e.g., starship.python.net:
8000 , or 127.0.0.1:80). For HTTP, the socket is usually connected to port number
Climbing the CGI Learning Curve| 1137