我遵循这个answer,我想使用render_模板来调用我的html文件,而不是直接在py中运行plot。在
我想用一些类似的东西:return render_template('hello.html', plot_url)
而不是:
^{pr2}$
我的问题是,是否有任何方法可以将plot传递到html文件,然后在flask中运行它?在
编辑:@app.route('/')
def build_Plot():
y = [1, 2, 3, 4, 5]
x = [0, 2, 1, 3, 4]
plt.plot(x, y)
output = io.BytesIO()
plt.savefig(output, format='png')
output.seek(0)
plot_data = base64.b64encode(output.getvalue()).decode()
return render_template("home.html", url=plot_data)
在主页.html公司名称:
MyFlaskApp{% block body %}
{% endblock %}