[英]I can't see continuously the last insert data from my MySQL database to my html page
I use flask framework and with this code i get the last insert data,but i want to display continuously the last insert.我使用 flask 框架并使用此代码获得最后插入数据,但我想连续显示最后插入。 When i reboot the flask framework i get it.Any help?
当我重新启动 flask 框架时,我明白了。有帮助吗?
app.py应用程序.py
@app.route("/sensor" , methods=['POST','GET'])
def sensor():
cursor = db.cursor()
cursor.execute("SELECT Id,temperature,humidity FROM Bseonsor WHERE Id=(SELECT MAX(Id) FROM Bseonsor)")
results = cursor.fetchall()
return render_template('sensor.html',results=results)
sensor.html传感器.html
<div>
<table border="1" cellpadding="5" cellspacing="5">
{% for row in results %}
<tr> {{ row[1] }} {{ row[2] }} </tr>
{% endfor %}
</table>
</div>
I believe when making selections to the database, you should use the buffered=True
argument.我相信在对数据库进行选择时,您应该使用
buffered=True
参数。
Note about selections: Also in the above program, the specified the size is 2 to fetch two records.关于选择的注意事项:同样在上述程序中,指定大小为 2 以获取两条记录。 Also, we set buffered=True in connection.
此外,我们在连接中设置了 buffered=True。 Cursor () method to avoid MySQL Unread result error.
Cursor() 方法避免 MySQL 未读结果错误。
About mysql-connector selections 关于 mysql-connector 选择
It should look something like this: cursor = db.cursor(buffered=True)
This can be a bit of a pain when trying to use prepared SQL though.它应该看起来像这样:
cursor = db.cursor(buffered=True)
不过,当尝试使用准备好的 SQL 时,这可能会有点痛苦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.