我是web dev的新手,我必须创建一个实时仪表板,我有sqlite数据库,它从设备接收数据,我使用烧瓶,以检索数据显示它。我的问题是我可以' t使用socketio来刷新我的数据而不刷新页面,所以用ajax和jquery会很有用,任何人都可以帮助我。
Flask代码:
from flask import Flask, render_template, request
app = Flask(__name__)
app.debug = True
import sqlite3
import datetime
import time
# Retrieve data from database
@app.route("/get_data")
def getData():
conn=sqlite3.connect('sagemdb')
curs=conn.cursor()
DateTimee = datetime.time()
memUsage = 0
for row in curs.execute("SELECT * FROM STBdata"):
DateTimee = str(row[0])
memUsage = row[1]
conn.close()
return DateTimee, memUsage
# main route
@app.route("/")
def index():
DateTimee1, memUsage1 = getData()
templateData = {
'time': DateTimee1,
'memUsage': memUsage1,
}
return render_template('index.html', **templateData)
if __name__ == "__main__":
app.run(host='127.0.0.1', port=4000)
**HTML Code :
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highstock Example</title>
</head>
<body>
<h3>{{time}}</h3>
<h3>{{memUsage}}</h3>
<div id="container" style="height: 400px; min-width: 310px"></div>
</body>
</html>
**