[英]Python html format all select table row
cursor.execute("""SELECT [APPL_NAME] ,[JOB_NAME],[LABE] FROM XYZ)
resultat = cursor.fetchall()
for row in resultat:
html_code = """
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<body>
<table border='1'
<tr>
<th>Date</th>
<th>Count</th>
<th>Status</th>
</tr>
<tr>
<td>{}</td>
<td>{}</td>
<td>{}</td>
</tr>
</table>
</body>
</html>""".format(row[0],row[1],row[3])
我正在嘗試從數據庫表中獲取記錄並通過電子郵件發送數據。 在表中選擇查詢 10-20 條記錄。 但是在電子郵件中只有一條記錄打印在上面的代碼表中。 我嘗試了列表中的所有數據,但沒有運氣。 請建議我如何格式化電子郵件中的所有選擇表記錄。 謝謝
你有糟糕的算法。 在循環中,您替換所有 html 代碼而不是添加新行。
cursor.execute("""SELECT [APPL_NAME],[JOB_NAME],[LABE] FROM XYZ""")
resultat = cursor.fetchall()
創建行:
rows_code = ""
for row in resultat:
rows_code = rows_code + """
<tr>
<td>{}</td>
<td>{}</td>
<td>{}</td>
</tr>
""".format(row[0],row[1],row[2])
創建完整的 html 代碼:
html_code = """
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<body>
<table border='1'
<tr>
<th>Date</th>
<th>Count</th>
<th>Status</th>
</tr>
{}
</table>
</body>
</html>
""".format(rows_code)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.