小编Mik*_*rom的帖子

如何在按下按钮后在 Flask 中显示图像

我是 Flask 和 Web 开发的新手。我想在按下网页上的按钮后在本地网络服务器上显示图像。我正在使用 Flask。我已经尝试解决这个问题有一段时间了,但还没有成功,所以任何帮助都将是令人难以置信的。烧瓶代码:

@app.route('/graph_select')
def graph_select():
    return render_template('live_stream.html')


@app.route('/read_ph', methods=["GET"])
def ph_plot():
    if request.method == "GET":
        all_plots.ph_plot()
        return render_template('live_stream.html')


@app.route("/read_temp", methods=["GET"])
def temp_plot():
    if request.method == "GET":
        all_plots.temperature_plot()
        return render_template('live_stream.html')


@app.route('/read_distance', methods=["GET"])
def distance_plot():
    if request.method == "GET":
        all_plots.distance_plot()
        return render_template('live_stream.html')
Run Code Online (Sandbox Code Playgroud)

HTML 代码:

    <h1>Data Monitoring Station</h1>

      <form method="GET" 
        <a href="read_temp"><button type="button">Temperature Graph</button></a>
        <a href="read_ph"><button type="button">PH Graph</button></a>
        <a href="read_distance"><button type="button">Distance Graph</button></a>
      </form>

    <h3><img src="{{ url_for('static', filename='ph_plot.png') }}" width="30%">$
    <h3><img src="{{ url_for('static', filename='temperature_plot.png') }}" width="30%">$
    <h3><img src="{{ url_for('static', filename='distance_plot.png') …
Run Code Online (Sandbox Code Playgroud)

html python flask

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

标签 统计

flask ×1

html ×1

python ×1