在 Flask 路由中捕获以查询字符串作为参数的 URL

Jac*_*rry 5 python flask

Flask 有没有办法接受完整的 URL 作为 URL 参数?

我知道<path:something>接受带斜杠的路径。但是,我需要接受所有内容,包括之后的查询字符串?,并且path不会捕获它。

http://example.com/someurl.com?andother?yetanother
Run Code Online (Sandbox Code Playgroud)

我想捕捉someurl.com?andother?yetanother。我不提前知道将提供什么查询参数(如果有)。我想避免从 重建查询字符串request.args

Doo*_*beh 3

path模式将让您捕获更复杂的路由模式,例如 URL:

@app.route('/catch/<path:foo>')
def catch(foo):
    print(foo)
    return foo
Run Code Online (Sandbox Code Playgroud)

过去的数据?表明它是一个查询参数,因此它们不会包含在该模式中。您可以访问该零件表单,也可以根据评论中提到的方式request.query_string构建它。request.args