【发布时间】:2020-03-04 06:23:50
【问题描述】:
这是我的app.py文件mysql查询正常检索数据
@app.route('/dashboard', methods=['GET', 'POST'])
#@is_logged_in
def dashboard():
form = GenreForm(request.form)
if request.method == 'POST':
genre = request.form['genre']
cur = mysql.connection.cursor()
result = cur.execute("""SELECT * FROM music_src WHERE type_of_music = %s"""(genre,))
if result > 0:
data = cur.fetchone()
else:
return redirect(url_for('dashboard'))
cur.close()
return redirect(url_for('search', data=data))
这是我的 search.html 代码
{% extends 'layout.html' %}
{% block body %}
<table border="1" bordercolor="white" cellpadding="15" cellspacing="35" style="font-family:Georgia, Garamond, Serif;color:white;font-style:italic;">
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>Type_of_music</th>
</tr>
</thead>
<tbody>
{% for row in data %}
<tr>
<td>{row[0]}</td>
<td>{row[1]}</td>
<td>{row[2]}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
当我调试 mysql 查询时传递如下数据。这就是它不打印的原因吗?如果是这样,我如何以 ID Title 和 Type_of_music 的表格格式打印它
data={'id':+28,+'title':+'Once+upon+a+time+–+James+Bond',+'type_of_music':+'sad'}
【问题讨论】:
标签: python mysql python-3.x flask html-table