Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle HTML Form Data with Python?

Tags:

python

html

forms

I'm trying to use Python and HTML together. What I'm trying to do is create an HTML Form that will submit data to a python file and that python file will then handle the data. But I'm not getting it 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 ends up happening is I just see my python code in the browser, the file doesn't begin handling the data.

What can I do?

like image 751
mrfixit4u Avatar asked Feb 13 '13 19:02

mrfixit4u


1 Answers

You should know, that you are getting plain python source document via http protocol now. If you want to use CGI mechanism, you should place youre .py in cgi-enabled directory. It means that you need http server.

related questions

  • How to run Python CGI script
  • How do I set up a Python CGI server?
like image 114
bsiamionau Avatar answered Oct 04 '22 18:10

bsiamionau