且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在python flask中,如何在route函数之外获取path参数?

更新时间:2023-02-23 22:42:15

可以使用request.view_args. 文档对此定义如下:

It's possible to use request.view_args. The documentation defines it this way:

与请求匹配的视图参数字典.

A dict of view arguments that matched the request.

这是一个例子:

@app.route("/data/<section>")
def data(section):
    assert section == request.view_args['section']