python - When i am going to fectch data from mysql database table it gives output in the fomt of {coloumn_name:data}
问题描述
This Is My Python Code
@app.route('/customer')
def admin_customer():
cur=mysql.connection.cursor()
res=cur.execute("SELECT NUM,USERNAME,USEREMAIL,MOBILE FROM customertable")
cur.execute("SELECT * FROM customertable")
data = cur.fetchall()
print(data)
return render_template('users.html', data=data)
My Html code
{% for row in data %}
<tr>
<td>{{row.0}}</td>
<td>{{row.1}}</td>
<td>{{row.2}}</td>
</tr>
{%endfor%}
output photo My Output photo
解决方案
我不确定您面临什么问题,因为您没有向我们显示任何错误。但是,就我而言,这是mysql
图书馆的预期行为。要正确呈现您的列表,请按名称访问字典键:
{% for row in data %}
<tr>
<td>{{row.USERID}}</td>
<td>{{row.USERNAME}}</td>
<td>{{row.USEREMAIL}}</td>
</tr>
{%endfor%}
推荐阅读
- javascript - MongoDB 通过 findOne 加入集合
- prolog - 如何在prolog中打印出所有事实
- php - Laravel 日期/时间比较
- c# - 文本框中的特定字符
- c# - C#:更新 SQL Server 表中的数据
- linux - Android Studio 的菜单非常滞后,几乎无法使用
- chromium - 谷歌应用商店安卓 10
- javascript - 在 webdriverio 中模拟鼠标移出 - javascript
- java - 如何在右上角的应用栏后退箭头上获得返回按钮(在设备上)之类的功能
- c# - 当“&”符号存在时,.Net Core System.Web.HttpUtility.HtmlDecode 不起作用