problem running the cgi module

Kent Johnson kent37 at tds.net
Thu Mar 31 11:44:53 EST 2005


chris patton wrote:
> Hi everyone. I'm trying to code an HTML file on my computer to make it
> work with the cgi module. For some reason I can't get it running. This
> is my HTML script:
> 
> ------------------------------------------------------
> 
> <form method="post" action="C:\chris_on_c\hacking\formprinter.py">
> <b><i><font size="50">HOWDY!</font></b></i><br><br>
> 
> <input type="text" name="name" size="50" value=""><br><br>
> 
> <input type="submit" name="send" value="submit">
> </form>

You don't seem to be using a web server at all here - the form action is a file path, not a URL. So 
the browser is just going to the file system to get the .py file.

You can make a simple CGI server by
- create a directory caled cgi-bin
- put formprinter.py into it
- change the form action to action="/cgi-bin/formprinter.py"
- Open a dos console to the directory containing the cgi-bin directory
- run the command python -c "import CGIHTTPServer; CGIHTTPServer.test()"

(Don't do this with Python 2.4, it is broken - use 2.3 or 2.4.1)

Kent

> 
> ------------------------------------------------------
> 
> And here is the python program it's supposed to run with,
> formprinter.py:
> 
> ------------------------------------------------------
> 
> import cgi, cgitb
> cgitb.enable()
> 
> form = cgi.FieldStorage()
> print '<font size="12">%s</font><br>' % form['name']
> 
> ------------------------------------------------------
> 
> Whenever I press submit on the HTML document, it returns the code for
> "formprinter.py". Can someone tell me what I'm doing wrong?
> 
> -Thanks for any help!
> 



More information about the Python-list mailing list