The way CGI works is that your script is called every time the
corresponding HTML is loaded. You can access all the parameters sent
to the script using cgi.FieldStorage.
Note that hidden fields are passed in plain text format from/to the
server, don't send anything sensitive in them.
It could be None: cgi.FieldStorage().getvalue("hidden_attribute") ==
In CGI you don't wait, the script exists and called again when use
hits a button/refresh ...
There are many other ways (AJAX, Web frameworks, FastCGI ...). However
I'd recommend you start with plain CGI which is *simple*.
Here is a small example:
import cgitb; cgitb.enable() # Show errors in HTML output
from cgi import FieldStorage
FUNNY = [ "mickey", "donald", "daisy", "minnie", "goofy" ]
print "Content-Type: text/html"
form = FieldStorage()
query = form.getvalue("query", "")
<input type="text" name="query" value="%s">
<input type="submit" value="search">
''' % query
for someone in FUNNY:
if query in someone:
print "<br />%s" % someone
if __name__ == "__main__":
Note that your script directory is automatically added to the path.
Make sure "mod_cgi" is uncommented, set your document root and set
right python interpreter in cgi.assign