- #!/usr/bin/python
- ### Python CGI Example
- ### Author: TorrentialStorm
- import sys, os
- import cgi, urlparse, Cookie
- import cgitb
- cgitb.enable()
- def main():
- print "Content-Type: text/html"
- print
- QUERY_STRING = os.environ.get("QUERY_STRING")
- if QUERY_STRING != None:
- _GET = urlparse.parse_qs(QUERY_STRING, True)
- else:
- _GET = {}
- HTTP_COOKIE = os.environ.get("HTTP_COOKIE")
- _COOKIE = Cookie.SimpleCookie()
- if HTTP_COOKIE != None:
- _COOKIE.load(HTTP_COOKIE)
- print "Environment vars:<br/>"
- for key in os.environ.keys():
- print "%s<br/>" % (key)
- print "<br/><br/>GET vars:<br/>"
- for key in _GET.keys():
- print "GET[%s] = %s<br/>" % (key, _GET[key])
- print "<br/><br/>Cookies:<br/>"
- for key in _COOKIE.keys():
- print "COOKIE[%s] = %s<br/>" % (key, _COOKIE[key].value)
- if __name__ == '__main__':
- main()
Python CGI
Posted by Admin on Tue 16th Mar 2010 00:07
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.