如何获取Flask请求的url的不同部分? [英] How do I get the different parts of a Flask request's url?

查看:189
本文介绍了如何获取Flask请求的url的不同部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测请求是来自 localhost:5000 还是 foo.herokuapp.com 主机,请求什么路径。如何获取有关Flask请求的信息?

可以通过几个 Request 字段


用户请求以下URL:

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

在这种情况下,

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


您可以轻松地提取主持人部分与适当的分裂。

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?

解决方案

You can examine the url through several Request fields:

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/

You can easily extract the host part with the appropriate splits.

这篇关于如何获取Flask请求的url的不同部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆