[Tutor] CGI HELP

Joel Goldstick joel.goldstick at gmail.com
Wed Oct 6 11:54:03 CEST 2010


On Wed, Oct 6, 2010 at 5:25 AM, Dipo Elegbede <delegbede at dudupay.com> wrote:

> Hi all,
>
> I wrote this code as an example from a book:
>
> #!c:\Python26\python.exe
> # Program displaying CGI environment variables.
>
> import os
> import cgi
>
> def printHeader(title):
> print """Content-type: text/html
>
> <?xml version = "1.0" encoding = "UTF-8"?>
> <! DOCTYPE html PUBLIC
> "-//W3C//DTD XHTML 1.0 Strict//EN"
> "DTD/xhtml1-strict.dtd">
> <html xmlns = "http://www.w3.org/1999/xhtml">
> <head><title>%s</title></head>
>
> <body>""" % title
>
> rowNumber = 0
> backgroundColour = "white"
>
> printHeader("Environmental Variables")
> print """<table style = "border: 0">"""
>
> # print table of cgi variables and values
> for item in os.environ.keys():
> rowNumber += 1
>
> if rowNumber % 2 == 0: # even row numbers are white
> backgroundColour = "white"
> else: # odd row numbers are grey
> backgroundColour = "lightgrey"
>
> print """<tr style = "background-color: %s">
> <td>%s</td><td>%s</td</tr>""" %(backgroundColour,
> cgi.escape(item), cgi.escape(os.environ[item]))
> print """</table></body></html>"""
>
> It was supposed to return a list of environmental variables in a given
> order.
> Sadly only the header displayed.
> I have looked through over and over, please what am i doing wrong.
> This is from Deitel How to program python, Chapter 6.
>
> thanks and best regards.
> --
>
did you lose the indentation in copying code to email?

-- 
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101006/ab16489f/attachment.html>


More information about the Tutor mailing list