gpt4 book ai didi

python - 你如何访问 Flask 路由中的查询字符串?

转载 作者:IT老高 更新时间:2023-10-28 12:06:14 25 4
gpt4 key购买 nike

如何访问 Flask 路由中的查询参数或查询字符串?这在 Flask 文档中并不明显。

下面的示例路由 /data 说明了我想要访问该数据的上下文。如果有人请求 example.com/data?abc=123 之类的东西,我想访问字符串 ?abc=123 或能够检索参数的值比如abc

@app.route("/data")
def data():
# query_string = ???
return render_template("data.html")

最佳答案

from flask import request

@app.route('/data')
def data():
# here we want to get the value of user (i.e. ?user=some-value)
user = request.args.get('user')

关于python - 你如何访问 Flask 路由中的查询字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11774265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com