我制作了一个小烧瓶应用程序,该应用程序从MySQL源中提取数据并将其放入表中,但是MySQL数据未正确填充表中。 (编辑-通过这个,我的意思是我根本就没有人口)
mydb = mysql.connector.connect(
host=x,
user=x,
passwd=x,
database=x
)
def browserSettings_mysql():
curs = mydb.cursor()
curs.execute("SELECT DATE_FORMAT(dtime, '%Y-%m-%d %T') as timest, moisture, temp FROM moisture")
return curs.fetchall()
@app.route('/')
def index():
return render_template("index.html", rows = moistureControl.browserSettings_mysql())
<table>
<tr>
<th>Time</th>
<th>Temp</th>
<th>Moisture</th>
</tr>
{% for row in rows %}
<tr>
<td>{{row.timest}}</td>
<td>{{row.temp}}</td>
<td>{{row.moisture}}</td>
</tr>
{% endfor %}
</table>
我该如何解决?
答案 0 :(得分:1)
您的row对象是一个元组列表。您将必须按索引访问数据(例如,row[0]
而不是row.timest
)。
<table>
<tr>
<th>Time</th>
<th>Temp</th>
<th>Moisture</th>
</tr>
{% for row in rows %}
<tr>
<td>{{row[0]}}</td>
<td>{{row[2]}}</td>
<td>{{row[1]}}</td>
</tr>
{% endfor %}
</table>