前几天我在堆栈溢出中看到如何使用函数重定向..但它在这里不起作用
#!/Python27/python
import cgi
import cgitb ; cgitb.enable()
import MySQLdb
from datetime import datetime
f= cgi.FieldStorage()
l=f["roll"].value
def redirect(url):
print "Content-Type: text/plain"
print "Refresh: 0; url='%s'" % url
print
print "Redirecting..."
Con = MySQLdb.Connect(host="127.0.0.1", port=3306, user="root", passwd="jesus", db="student")
cursor = Con.cursor()
sql="SELECT YEAR FROM STDDET WHERE id='%s'"%(l)
cursor.execute(sql)
data=cursor.fetchone()
cyear=datetime.now().year
cmonth=datetime.now().month
data=data[0]
data=int(data)
year=cyear-data
print year
if(year==3):
redirect("intro.html")
elif(year==4):
redirect("yea4.html")
即使满足 if 条件,它也不会被重定向...我收到错误格式错误的标题...请帮助!