I have the following directives in my Apache 2 virtual host configuration:
<Directory /var/www/foo_test>
Options MultiViews +ExecCGI
AddHandler cgi-script .py
AllowOverride All
</Directory>
I have the following simple form HTML:
<html>
<body>
<form action="foo.py" method="post" id="foo_form">
<input type="text" id="foo" />
<input type="submit" />
</form>
</body>
</html>
Here is foo.py
, the executable script that is called when the form is submitted:
#!/usr/bin/env python
import cgi
arguments = cgi.FieldStorage()
print "Content-Type: text/html\n"
print repr(arguments)
When I submit the form, I get the following response:
FieldStorage(None, None, [])
There is nothing in the FieldStorage
object instance that contains values for the fields specified in the form foo_form
.
If I replace the Python script with a Perl script and its CGI
module, along with changing the Apache directives to handle Perl CGIs, I have no problems reading fields out of the form. This suggests to me that my Apache setup is okay.
However, am I missing something with instantiating the cgi.FieldStorage()
object, or with my Apache setup, that is causing the form submission to fail?
You need to give the input a name
attribute if you want its data to be submitted in the form.