I am creating HTML form and using Python to code it. I have installed Apache version2.2 and Python version 2.6. Here is the code:
#!C:\Python26\Python.exe -u
#import cgi modules
import cgi
#create instances of field storage
form = cgi.FieldStorage()
#get data from the fields
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Hello - Second CGI Program</title>"
print "</head>"
print "<body>"
print "<h2>Hello %s %s</h2>" % (first_name, last_name)
print "</body>"
print "</html>"
The code I have written gives me an internal error. But, when I remove the following lines it runs fine.
#import cgi modules
import cgi
#create instances of field storage
form = cgi.FieldStorage()
开发者_高级运维
#get data from the fields
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')
I edited the httpd config file and added lines:
AddHandler cgi-script .cgi .py .pl
ScriptAlias /cgi-bin/ "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/"
Why is internal error message being displayed when the lines are added? And, I am new to building HTML forms in Python. Suggestions on tutorials on HTML form using Python for Windows would be really helpful. Thanks.
PS: The files containing script are located in cgi-bin Apache folder.
Something is definitely wrong is you subtracted those lines, and it still ran. print "<h2>Hello %s %s</h2>" % (first_name, last_name)
in your HTML body should raise an exception, given that they are not defined yet.
Please post the bits of your error.log for the Internal Server Error.
精彩评论