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

(yzsuai) #1

of CGI scripts, after all. Let’s start using this to better advantage now, and write a Python
script that builds up response HTML programmatically, listed in Example 15-5.


Example 15-5. PP4E\Internet\Web\cgi-bin\tutor2.py


#!/usr/bin/python


print("""Content-type: text/html


CGI 101

A Third CGI Script




Hello, CGI World!



""")

for i in range(5):
print('

')
for j in range(4):
print('' % (i, j))
print('')


print("""


%d.%d



""")

Despite all the tags, this really is Python code—the tutor2.py script uses triple-quoted
strings to embed blocks of HTML again. But this time, the script also uses nested Python


Figure 15-4. A page with an image generated by tutor1.py


Climbing the CGI Learning Curve| 1147
Free download pdf