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

(yzsuai) #1

Figure 15-11. Reply page generated by tutor4.py


As usual, we can pass parameters to this CGI script at the end of a URL, too. Fig-
ure 15-12 shows the page we get when passing a user and age explicitly in this URL:


http://localhost/cgi-bin/tutor4.py?user=Joe+Blow&age=30

Figure 15-12. Reply page from tutor4.py for parameters in URL


Notice that we have two parameters after the? this time; we separate them with &. Also
note that we’ve specified a blank space in the user value with +. This is a common URL
encoding convention. On the server side, the + is automatically replaced with a space
again. It’s also part of the standard escape rule for URL strings, which we’ll revisit later.


1160 | Chapter 15: Server-Side Scripting

Free download pdf