我有一個 json 檔案,其中資料是一個串列,字典作為資料我需要做的是以索引 0 為例,并回傳名字、郵件和用戶名鍵值。json 資料是這樣的:[{},{},{},{}]
這是我現在的代碼:
@app.route("/showallusers")
def show_users():
temp_list = []
with open("users.json") as file:
file = json.load(file)
res = """
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table>
<thead>
<tr>
<th>Navn</th>
<th>Brugernavn</th>
<th>Email</th>
</tr>
</thead>
<tbody>
"""
i = 0
for i in len(file):
res = """<tr>"""
j = 0
for j in len(file):
res = """<td>""" f"{file[i]}" """</td>"""
res = """</tr>"""
res = """
</tbody>
</table>
</body>
</html>
"""
return res
該表應如下所示,并應為串列中的每個字典重復添加帶有表資料的表行:|Name|Username|Mail| |:---|--------|--------------| |bob|bob1234 |[email protected]|
uj5u.com熱心網友回復:
你的 for 回圈會變成這樣:
for row in file:
res = """<tr>"""
for key, value in row.items():
res = f"""<td> {value} </td>"""
res = """</tr>"""
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/349226.html
