Posting html form values to python script

Vittal Cherala picture Vittal Cherala · Apr 12, 2013 · Viewed 79.3k times · Source

I have created html form with text box and button

enter ur search keyword

My requirement is to pass the text box value in to my test.py code, is there any way to do it. Please suggest me how do it.

Answer

scottydelta picture scottydelta · Apr 12, 2013

in the form action form action="", put the location of your cgi script and the value of the textbox will be passed to the cgi script. eg.

<form name="search" action="/cgi-bin/test.py" method="get">
Search: <input type="text" name="searchbox">
<input type="submit" value="Submit">
</form> 

in your test.py

import cgi
form = cgi.FieldStorage()
searchterm =  form.getvalue('searchbox')

thus you will get the key word entered in search text box in searchterm variable in python.