Debug python CGI

Skip Montanaro skip at pobox.com
Sat Jan 26 17:51:41 EST 2002


    Steven> Does the python CGI module have a test mode where the script can
    Steven> be executed from a command line instead of web server?  

I will ignore the excellent advice all the other people gave you. ;-)

Once you get to the point where you test it using an actual web server, you
might want to check out the cgitb module.  At the top of your script, add
these two lines before any other imports:

    import cgitb
    cgitb.enable(display=1)

When your CGI script barfs (and you know it will ;-), it will do so in a
beautiful, multi-hued, gonzo traceback fashion.  About the only thing it
doesn't do for you is display the values of the script's <input>s, though it
does display the local variables of the barfing function.

-- 
Skip Montanaro (skip at pobox.com - http://www.mojam.com/)




More information about the Python-list mailing list