gpt4 book ai didi

python - 在 flask 中获取原始查询字符串

转载 作者:太空狗 更新时间:2023-10-30 00:45:34 27 4
gpt4 key购买 nike

有没有办法在 Flask 中获取原始查询字符串或查询字符串参数列表?我知道如何使用 request.args.get('key') 获取查询字符串参数,但我希望能够接收可变查询字符串并自行处理它们。这可能吗?

最佳答案

several request attributes让您访问原始网址:

Imagine your application is listening on the following URL:

http://www.example.com/myapplication

And a user requests the following URL:

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

In this case the values of the above mentioned attributes would be the following:

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/

这些,最终借助urlparse , 会让你提取你需要的信息:

 >>> from urlparse import urlparse
>>> urlparse(request.url).query
'x=y'

关于python - 在 flask 中获取原始查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17093372/

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