【发布时间】:2019-02-24 18:18:00
【问题描述】:
我对 Bootstrap 中的 mysql db python 表有疑问。
我的问题是我的数据没有显示在表格中。我可以看到它获取数据,因为当我在 mysql db 中添加带有数据的行时,表会增加。
app.py 代码:
@app.route('/dashboard')
@is_logged_in
def dashboard():
#create cursor
cur = mysql.get_db().cursor()
#Get data
result = cur.execute("SELECT * FROM test")
data=cur.fetchall()
if result > 0:
return render_template('dashboard.html', data=data)
else:
msg = 'No DOC Found'
return render_template('dashboard.html', msg=msg)
#close connection
cur.close()
return render_template('dashboard.html' )
.html
<table class="table table-striped">
<tr>
<th>data1</th>
<th>data2</th>
</tr>
{% for test in data%}
<tr>
<td>{{test.rdno}}</td>
<td>{{test.ipno}}</td>
{% endfor %}
</tr>
</table>
【问题讨论】:
-
你检查过这个问题是否有可能的解决方案:stackoverflow.com/questions/9845102/using-mysql-in-flask