【问题标题】:How to get just the arguments of a request in Flask? [duplicate]如何在 Flask 中获取请求的参数? [复制]
【发布时间】:2023-05-10 03:44:01
【问题描述】:

我在 * 上找到了这篇文章:
How do I get the different parts of a Flask request's url?
我们可以像这样获取请求的不同部分:

With this URL :

  http://www.example.com/myapplication/page.html?x=y

We can get these values :

  path             /page.html
  script_root      /myapplication
  base_url         http://www.example.com/myapplication/page.html
  url              http://www.example.com/myapplication/page.html?x=y
  url_root         http://www.example.com/myapplication/

有没有办法获取字符串的最后一部分(参数)?
--> 得到这个:?x=y

谢谢!

【问题讨论】:

标签: python flask request


【解决方案1】:

使用request.args

@app.route(...)
def some_method():
    args = request.args
    print(args)

【讨论】:

  • 谢谢,但我想将所有参数存储在这样的字符串中:?x=y
  • @PacCol 为什么?你想做什么?
  • 我想编辑 url_root。
  • @PacCol 对我来说仍然没有太多解释。我没有足够的上下文,您似乎有一个 XY Problem