Flask 获取 request url 的各个部分
Get the different parts of a Flask request's url

我想获得请求时来自哪里以及访问的路径。如何从 Flask 的请求中获取这些信息?

I want to detect if the request came from where and what path was requested. How do I get this information about a Flask request?

flask

admin

https://stackoverflow.com/questions/15974730/how-do-i-get-the-different-parts-of-a-flask-requests-url

用户请求链接: ``` request: http://www.example.com/myapplication/page.html?x=y ``` 上述情况提到的属性值: ``` 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/ ```

A user requests the following URL: ``` request: 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/ ```

另一种示例: ``` request: http://127.0.0.1:5000/alert/dingding/test?x=y ``` 结果: ``` request.url: http://127.0.0.1:5000/alert/dingding/test?x=y request.base_url: http://127.0.0.1:5000/alert/dingding/test request.url_charset: utf-8 request.url_root: http://127.0.0.1:5000/ str(request.url_rule): /alert/dingding/test request.host_url: http://127.0.0.1:5000/ request.host: 127.0.0.1:5000 request.script_root: request.path: /alert/dingding/test request.full_path: /alert/dingding/test?x=y request.args: ImmutableMultiDict([('x', 'y')]) request.args.get('x'): y ```

Another example: ``` request: http://127.0.0.1:5000/alert/dingding/test?x=y ``` Result: ``` request.url: http://127.0.0.1:5000/alert/dingding/test?x=y request.base_url: http://127.0.0.1:5000/alert/dingding/test request.url_charset: utf-8 request.url_root: http://127.0.0.1:5000/ str(request.url_rule): /alert/dingding/test request.host_url: http://127.0.0.1:5000/ request.host: 127.0.0.1:5000 request.script_root: request.path: /alert/dingding/test request.full_path: /alert/dingding/test?x=y request.args: ImmutableMultiDict([('x', 'y')]) request.args.get('x'): y ```