Few Small Questions Regarding CGI

Mel mwilson at the-wire.com
Tue Feb 16 01:36:55 CET 2010

joy99 wrote:

> Dear Group,
> I am trying to learn CGI. I was checking Python Docs. There are
> multiple modules. Which one to start with?
> Is there any other material or URL for step by step learning of CGI.
> My next question is:
> I want to test it. I have a small personal computer. I have internet
> but is connected by a service provider. I do not have personal web
> page. Can I use my personal computer as a client as well as a server?

A server can be as simple as:

#!/usr/bin/env python
# -*- coding: ASCII -*-
'''Simple CGI server in Python
import getopt, os, sys
from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler

port = 8000
opts, args = getopt.getopt (sys.argv[1:], 'd:p:', ['www=', 'port='])
for o, v in opts:
    if o in ['-d', '--www']:
        os.chdir (v)
    elif o in ('-p', '--port'):
        port = int (v)
handler = HTTPServer (('', port), CGIHTTPRequestHandler)

If you run this like

mycgiserver.py --www=my_www_dir

and put your web pages under my_www_dir, and your CGI programs under 

then pointing your browser to <http://localhost:8000/> will show you your 


More information about the Python-list mailing list