Web Application
Your own CGI web server on localhost
code by effbot:
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()
- create directory for CGI server, ie. /cgihome with subdirectories ./cgi and ./server
- 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
Introduction
*
Using templates
- htmltmpl is the best from simple templating engines: has all you need, but no extra features! :-)
- TurboGears has excellent KID template system
Comments (0)
You don't have permission to comment on this page.