No need to struggle with configuring Apache web server if all you need is simple CGI server. Host your own:

Your own CGI web server on localhost

import CGIHTTPServer
import BaseHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
    cgi_directories = ["/cgi"]
PORT = 8000
httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()

Code by effbot:

  • create directory for CGI server, ie. /cgihome with subdirectories ./cgi and ./server.
  • /cgihome (on Windows) should be top-level directory (and never use spaces in file/directory names). On Linux, you can place it directly in your home (~), so it might be ~/cgihome. Don't put it too deep. / in the beginning means 'root' :-)
  • save code above as file cgihttpserver.py into directory /cgihome/server
  • open commadline teminal, and run commands "cd /cgihome" and "python server/cgihttpserver.py" - server runs at localhost, port 8000
    • on Windows, you can also create icon to run it
  • put any static html page into /cgihome - it is served from http://localhost:8000/page.html
  • put any CGI program into /cgihome/cgi - it is served http://localhost:8000/cgi/scriptname.py
  • to stop server, close the commandline window
  • you can see any activities (and errors) in that terminal window
  • don't forget to close terminal when you don't need it anymore.

Introduction - Simple applications

Using templates

  • htmltmpl is the best from simple templating engines: has all you need, but no extra features! :-) Preinstalled on Ubuntu
  • TurboGears has excellent KID template system

On Windows

Another web server

  • Simple web server - cd to the the directory you want to serve, type in the one liner in the command line “python -c 'import SimpleHTTPServer; SimpleHTTPServer.test()'” and proceed to http://localhost:8000/ via browser


Page Information

  • 1 month ago [history]
  • View page source
  • You're not logged in
  • No tags yet learn more

Wiki Information

Recent PBwiki Blog Posts