我在windows上使用2.7.8。我对这种情况发生的原因感到紧张并为此进行了大量搜索。就像我把cgi代码放在第1位并检查它工作正常但当我只是放置import MySQLdb
时它不会执行而页面显示server error
。
这里是没有import MySqldb
成功打印的代码:
文件名:cgisql.py
#!C:\Python27\python
# Import modules for CGI handling
import cgi
# 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 "<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>"
使用导入MySqldb
#!C:\Python27\python
# Import modules for CGI handling
import cgi
import MySQLdb
# 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 "<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>"
页面上的输出:
很抱歉有更长的描述bcz我面临一些大问题,老实说,我不知道这个谜是什么.......