Local execution of Python CGI scripts  Hot PDF Print E-mail
Tag it:
Delicious
Furl it!
Digg
NewsVine
Reddit
YahooMyWeb
Technorati
Articles Reviews Python
Written by Eli Bendersky   
Tuesday, 09 September 2008

Here’s a method to run Python CGI scripts locally, for testing. It employs the BaseHTTPServer and CGIHTTPServer standard modules to run a simple CGI-capable web server on your computer.

Here’s the code implementing the server:


import CGIHTTPServer
import BaseHTTPServer

class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
    cgi_directories = ["/cgi"]

PORT = 9999

httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()


This server assumes the directory it was run in is the root directory. It will run CGI scripts from the directory cgi, relative it its root. Place the following simple script in cgi and call it test.py:  

Read more ... click here


User reviews

There are no user reviews for this item.

Add new review




Powered by jReviews

Last Updated ( Tuesday, 09 September 2008 )
 
< Prev   Next >