小编陳俊良*_*陳俊良的帖子

如何刷新烧瓶网页?

最近,我有一个项目是在网页上实现动态绘图.

这是我的python代码

from flask import Flask
#from flask import render_template
import matplotlib.pyplot as plt
import io
import base64

app = Flask(__name__)

@app.route('/plot')
def build_plot():

    img = io.BytesIO()

    y = [1,2,3,4,5]
    x = [0,2,1,3,4]
    plt.plot(x,y)
    plt.savefig(img, format='png')
    img.seek(0)

    plot_url = base64.b64encode(img.getvalue()).decode()

    return '<img src="data:image/png;base64,{}">'.format(plot_url)
if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')
Run Code Online (Sandbox Code Playgroud)

这是我的HTML代码

<!DOCTYPE html>
<html>
    <head>
        <title> Plot</title>
        <meta content='5; url=http://127.0.0.1:5000/plot' http-equiv='refresh'>
    </head>
    <body>
        <img src="data:image/png;base64, {{ plot_url }}">
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

虽然我添加<meta content='5; url=http://127.0.0.1:5000/plot' http-equiv='refresh'>到我的HTML代码中,但它仍然无法自动刷新.

如果我想观察绘图的变化,我仍然需要手动刷新它.

任何人都可以帮我解决这个问题吗?非常感谢

html python flask

5
推荐指数
1
解决办法
1万
查看次数

How to exit mqtt forever_loop?

I created a program to receive data, recently.

And I want to break the loop When I receive a specific data.

For example, if I receive "1" to another machine, then my system will regard it as an illegal number, then it will break the loop to stop receiving data.

Here is my code in the below, and you can also see client.loop_stop() in my code. But it not works.

I have also tried sys.exit() in my code.

Although it …

python mqtt

1
推荐指数
1
解决办法
2056
查看次数

标签 统计

python ×2

flask ×1

html ×1

mqtt ×1