[英]Python - import MySQLdb in a CGI script not working in a browser
[英]MySqldb and CGI are not working together
我在Windows上使用2.7.8。我对此发生的原因感到紧张并为此进行了大量搜索。 就像我将cgi代码放置在1st并检查它是否工作正常,但是当我只放置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>"
在页面上输出:
抱歉,较长的描述,因为我正面临一些大问题,老实说,我不知道这个谜是什么.......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.