我试图用python和html制作一个python模板

时间:2016-12-28 07:08:42

标签: python

这段代码有什么问题吗? 我似乎无法找到任何问题,我仍然是python的新手。我使用HTML表单操作来执行代码,但它出现了500内部服务器错误...

#!/usr/bin/python

import MySQLdb
import time
import cgi
import cgitb
cgitb.enable()

localtime = time.asctime( time.localtime(time.time()) )

# Open database connection
db = MySQLdb.connect("localhost","root","root","TAS" )

# prepare a cursor object using cursor() method
cursor = db.cursor()

sql = "SELECT * FROM test_tbl WHERE id IN (SELECT MAX(id) FROM test_tbl)"

print "Content-type: text/plain;charset=utf-8\n"
try:
   # Execute the SQL command
   cursor.execute(sql)
   # Fetch all the rows in a list of lists.
   results = cursor.fetchall()
   for row in results:
       id = row[0]
       a1 = row[1]
       a2 = row[2]
       print "Wrote at:", localtime
       print "Fullname: %s" % (a1)
       print "NRIC: %s" % (a2)
       print "Sign by the Willer.                        ]\n"
       print "Our presence that involved on that day are ]\n"
       print "either by the willer request               ]\n"
       print "with the willer presence                   ]\n"
       print "and have appointed us as                   ]\n"
       print "the witnesses                              ]\n"
except:
       print "Error: unable to fecth data"
# disconnectc from server
db.close()

0 个答案:

没有答案