如何获取 Flask 请求 url 的不同部分? [英] How do I get the different parts of a Flask request's url?
本文介绍了如何获取 Flask 请求 url 的不同部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检测请求是否来自 localhost:5000
或 foo.herokuapp.com
主机以及请求的路径.如何获取有关 Flask 请求的信息?
I want to detect if the request came from the localhost:5000
or foo.herokuapp.com
host and what path was requested. How do I get this information about a Flask request?
推荐答案
你可以通过几个Request
字段:
You can examine the url through several Request
fields:
假设您的应用程序正在侦听以下应用程序根目录:
Imagine your application is listening on the following application root:
http://www.example.com/myapplication
并且用户请求以下 URI:
And a user requests the following URI:
http://www.example.com/myapplication/foo/page.html?x=y
在这种情况下,上述属性的值如下:
In this case the values of the above mentioned attributes would be the following:
path /foo/page.html
full_path /foo/page.html?x=y
script_root /myapplication
base_url http://www.example.com/myapplication/foo/page.html
url http://www.example.com/myapplication/foo/page.html?x=y
url_root http://www.example.com/myapplication/
您可以通过适当的拆分轻松提取主体部分.
You can easily extract the host part with the appropriate splits.
这篇关于如何获取 Flask 请求 url 的不同部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文