Few Small Questions Regarding CGI
Mel
mwilson at the-wire.com
Mon Feb 15 19:36:55 EST 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
$Id$'''
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)
handler.serve_forever()
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
my_www_dir/cgi-bin
then pointing your browser to <http://localhost:8000/> will show you your
site.
Mel.
More information about the Python-list
mailing list