我的目的是在网页上显示后端(flask)从串口接收的数据。后端测试过能发出json数据,前端试过直接读同目录下的.json文件,也是读不出来,但是查了下一些js和jquery的教程和问答,感觉没有什么问题啊,也引用jquery库了。代码如下:
@app.route('/')
def template():
return render_template('index.html')
@app.route('/_data', methods= ['GET','POST'])
def getdata():
ser=serial.Serial(port='COM4',baudrate=115200,timeout=3)
line=ser.readline()
num=line[line.find(":")+1:].strip()
if line.startswith("Temp"):
temp=num
arr={'temp':temp}
elif line.startswith("Humidity"):
humid=num
arr={'humid':humid}
return jsonify(arr)
温度:
湿度:
更改:
通过F12查看报错之后发现是$SCRIPT_ROOT没有定义。我按照[jqueryexample][1]里边在layout.html里边定义$SCRIPT_ROOT之后发现我的index.html和layout.html根本关联不起来,于是直接写在了index.html里边。
但是按照example那样把$SCRIPT_ROOT写在单独一个
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
php渲染的.应该看下php的渲染语法...本人对php不了解.
django的话是需要带 {{}}