problem running the cgi module

C

chris patton

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>

------------------------------------------------------

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!
 
P

pythonUser_07

I will take a guess that you might
1) make sure cgi is enabled in your webserver configuration
2) Probably must place the cgi script under $WEBSERVERDOCS/cgi-bin
unless you alter the configuration.

Also, the webserver might need to be configured to understand what
interpreter uses .py files. (not an issue on windows)

Good luck
 
K

Kent Johnson

chris said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,232
Messages
2,571,168
Members
47,803
Latest member
ShaunaSode

Latest Threads

Top