[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

Finally, adding a record works the same as in the GUI: fill in a new key and field values
and click Update; the CGI script creates a new class instance, fills out its attributes,
and stores it in the shelve under the new key. There really is a class object behind the
web page here, but we don’t have to deal with the logic used to generate it.
Figure 1-18 shows a record added to the database in this way.


Figure 1-17. peoplecgi.py update reply


Figure 1-18. peoplecgi.py after adding a new record


In principle, we could also update and add records by submitting a URL—either from
a browser or from a script—such as:


http://localhost/cgi-bin/
peoplecgi.py?action=Update&key=sue&pay=50000&name=Sue+Smith& ...more...

66 | Chapter 1: A Sneak Preview

Free download pdf