[Tutor] Testing CGI scripts offline

Michael P. Reilly arcege@shore.net
Wed, 17 Jan 2001 18:54:25 -0500 (EST)


> 
> Hi Guys,
> 
> Just wondering if theres any way i can use my home PC to test my CGI python 
> scripts, I'm sure theres a way to do it but i cant find one..
> 
> The script is a simple form checker.
> 
> Thanks in advance,
> 
> Jack

I suggest running the CGIHTTPServer that comes with Python
("Batteries Included").

Python 1.5.2 (#1, Aug 25 2000, 09:33:37)  [GCC 2.96 20000731 (experimental)] on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from BaseHTTPServer import HTTPServer
>>> from CGIHTTPServer import CGIHTTPRequestHandler
>>> import os
>>> os.chdir('/var/www')
>>> os.listdir('cgi-bin')
['printenv', 'test-cgi']
>>> serv = HTTPServer(("", 8080), CGIHTTPRequestHandler)
>>> serv.serve_forever()

Then set your browser to 'http://localhost:8080/cgi-bin/test-cgi'
and it will run the /var/www/cgi-bin/test-cgi program.  You can set
the directory as you need to; it could be a directory on a windoze box
or your home directory on UNIX or...

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------