从flask用`route()`装饰的函数如何接收参数?

我正在用烧瓶绘制Matplotlib图:

@app.route('/plot.png')
def plot_png():
    x = range(100)
    y = np.random.randint(0,100,100)
    fig = create_figure(x,y)
    output = io.BytesIO()
    FigureCanvas(fig).print_png(output)
    return flask.Response(output.getvalue(),mimetype='image/png')

有效
但我需要将参数提供给plot_png:

@app.route('/plot.png/<y>/')
def plot_png(y):
    x = np.arange(len(y))
    fig = create_figure(x,mimetype='image/png')

不起作用。

如何将参数提供给plot_png?
谢谢!

jbs1zgh 回答:从flask用`route()`装饰的函数如何接收参数?

按照书面规定,y将是一个字符串。

@app.route('/plot.png/<int:y>')

将解决此问题。如果需要,请添加斜杠。

本文链接:https://www.f2er.com/3141615.html

大家都在问