Processing HTML form data using Python?

I am trying to use Python and HTML together. What I'm trying to do is create an HTML form that will pass data to a python file and that python file will process the data. But I am not going to work.

Here is my Python code:

form = cgi.FieldStorage() # instantiate only once!

name = form['Sample Name'].value

and this is my html code:

<form method='POST' action='/functionGen.py'> 
Name: <input type='text' name='Sample Name'> 
<input type='submit' value='Begin Storing'> 
</form>

What ultimately happens is just to see my python code in a browser, the file does not start processing data.

What can I do?

+5
source share
1 answer

You should know that now you are getting a simple python source document via the http protocol. If you want to use the CGI mechanism , you must put youre.py in the cgi-enabled directory. This means you need an http server.

related issues

+2
source

All Articles