Example using QUERY_STRING : Query : CGI Web PYTHON TUTORIALS


PYTHON TUTORIALS » CGI Web » Query »

 

Example using QUERY_STRING


#!c:Pythonpython.exe
import os 
import cgi

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

<?xml version = "1.0" encoding = "UTF-8"?>    
<html>
<head><title>%s</title></head>
<body>""" % title

printHeader"QUERY_STRING example" )
print "<h1>Name/Value Pairs</h1>"

query = os.environ"QUERY_STRING" ]

if lenquery == 0:
   print """<paragraph><br />
      Please add some name-value pairs to the URL above.
      Or try 
      <a href = "index.py?name=YourName&amp;age=23">this</a>.
      </paragraph>"""
else:   
   print """<paragraph style = "font-style: italic">
      The query string is '%s'.</paragraph>""" % cgi.escapequery )
   pairs = cgi.parse_qsquery )

   for key, value in pairs.items():
      print "<paragraph>You set '%s' to value %s</paragraph>" 
         key, value )

print "</body></html>"



Leave a Comment / Note


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


PYTHON TUTORIALS

 Navioo CGI Web
» Query