我有一个功能,该功能从我正在使用 fetchall()的sql server数据库中检索数据,然后进行循环 检索到的数据全部打印在 cmd控制台上,但是当我尝试在模板上显示这些结果时,它仅显示最后一条记录。
def搜索(请求):
query = cursor.execute('Select id, fullname from person')
result = query.fetchall()
for row in result:
print("ID==>",id)
IPD=row[0]
return render(request,"test.html",{"IPD":IPD})
{{ IPD }}
答案 0 :(得分:0)
query = cursor.execute('Select id, fullname from person')
result = query.fetchall()
IPD=[]
for row in result:
print("ID==>",id)
IPD.append(row)
return render(request,"test.html",{"IPD":IPD})