Program to display CGI environment variables : Introduction : CGI Web PYTHON TUTORIALS


PYTHON TUTORIALS » CGI Web » Introduction »

 

Program to display CGI environment variables


#!c:Pythonpython.exe
import os
import cgi

def printHeadertitle ):
   print """Content-type: text/html

<?xml version = "1.0" encoding = "UTF-8"?>    
<html xmlns = "http://www.w3.org/1999/xhtml">
<head><title>%s</title></head>
<body>""" % title

rowNumber = 0
backgroundColor = "white"

printHeader( "Environment 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:         
      backgroundColor = "white"
   else:                          
      backgroundColor = "lightgrey"

   print """<tr style = "background-color: %s">
   <td>%s</td><td>%s</td></tr>""" % ( backgroundColor,
      cgi.escape( item ), cgi.escape( os.environ[ item ] ) )

print """</table></body></html>"""



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo CGI Web
» Introduction