15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

This HTML file presents a form to the user with an empty field for the user's name and a<br />

set of radio buttons for the user to choose from.<br />

1 <br />

2 Friends CGI Demo (static screen)<br />

3 <br />

4 Friends list for: NEW USER<br />

5 <br />

6 Enter your Name:<br />

7 <br />

8 How many friends do you have?<br />

9 0<br />

10 10<br />

11 25<br />

12 50<br />

13 100<br />

14 <br />

As you can see in the code, the form contains two input variables: person and howmany. The values of<br />

these two fields will be passed to our CGI script, friends1.py.<br />

You will notice in our example that we install our CGI script into the default cgi-bin directory (see the<br />

"Action" link) on the local host. (If this information does not correspond with your development<br />

environment, update the form action before attempting to test the Web page and CGI script.) Also,<br />

because a METHOD subtag is missing from the form action all requests will be of the default type, GET.<br />

We choose the GET method because we do not have very many form fields, and also, we want our query<br />

string to show up in the "Location" (aka "Address", "Go To") bar so that you can see what URL is sent to<br />

the server.<br />

Let us take a look at the screen that is rendered by friends.htm in a client (see Figure 20-4 for Safari on<br />

MacOS and Figure 20-5 for IE6). Throughout this chapter, we will feature screenshots from various Web<br />

browsers and operating systems over the past few years.<br />

Figure 20-4. Friends form page in Safari on MacOS X (friends.htm)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!