7

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?

mrfixit4u
  • 83
  • 1
  • 1
  • 4
  • 1
    If you're seeing python code in the browser then the problem is your server configuration rather than the code you've posted. What server are you using? Apache? – Endophage Feb 13 '13 at 19:56
  • It's better to use web frameworks to write webapps on python. Look at [Django](https://www.djangoproject.com/) which is pretty simple. – bsiamionau Feb 13 '13 at 19:58
  • @zvzdhk I'm not looking to write webapps, I already have a form prepared, I just want to be able to receive the information. – mrfixit4u Feb 13 '13 at 20:05
  • `What server are you using? Apache?` – bsiamionau Feb 13 '13 at 20:07
  • @zvzdhk I'm not using any server, I'm building this locally on my own computer. – mrfixit4u Feb 13 '13 at 20:22

1 Answers1

2

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

Community
  • 1
  • 1
bsiamionau
  • 8,099
  • 4
  • 46
  • 73