我是CGI初学者,尝试将输入从HTML传递到python(HTML文件输入到python文件)。我不知道我做错了什么。我正在学习http://www.tutorialspoint.com/python/python_cgi_programming.htm的教程,为了获得更多帮助,我还查看了Posting html form values to python script,但失败了。我正在使用Windows8OS。
这是我的代码:test.py#!C:\Python27\python
# Import modules for CGI handling
import cgi, cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')
print "Content-type:text/html\r\n\r\n"
print ""
print "
"print "
Hello - Second CGI Program"print ""
print "
"print "
Hello %s %s
" % (first_name, last_name)print ""
print ""
测试.html
Search:
在chrome上:当我写"http://localhost/cgi-bin/test.html"时,它给出:Server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
If you think this is a server error, please contact the webmaster.
Error 500
localhost
Apache/2.4.16 (Win32) OpenSSL/1.0.1p PHP/5.6.12
注意:我把test.py和test.html两个文件都放在“cgi-bin”中,对吗?因为我来自php、javascript等后台。
如果我做错了,请帮助我?