我编写了一个 python 脚本来查询我的数据库并以 HTML 表格格式显示数据。我怎样才能让这个代码以表格的形式显示到电子邮件中?
我尝试将代码粘贴在第二个脚本(EMAIL)上的 html 标记中,但它不会仅读取 HTML 的 Python 代码。
import pyodbc
import cgi
def htmlTop():
print("""Content-type:text/html\n\n
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>My Tabmle</title>
</head>
<body>""")
def selectCOAStatus(cnxn, cursor):
cursor.execute('''SELECT * from mytable''')
data = cursor.fetchall()
return data
def htmlTail():
print("""</body>
</html>""")
def connectDB():
conn_str = (
r'DRIVER={SQL Server};'
r'SERVER=test;'
r'DATABASE=test;'
r'Trusted_Connection=yes;'
)
cnxn = pyodbc.connect(conn_str)
cursor = cnxn.cursor()
return cnxn, cursor
def displayData(data):
print("<table border='1'")
print("<tr>")
print("<th>Date</th>")
print("<th>Count</th>")
print("<th>Status</th>")
print("</tr>")
for row in data:
print("<tr>")
print("<td>{0}</td>".format(row[0]))
print("<td>{0}</td>".format(row[1]))
print("<td>{0}</td>".format(row[2]))
print("</tr>")
print("</table>")
元芳怎么了
精慕HU
相关分类