【问题标题】:How to get the url of the requesting site with pyramid如何使用金字塔获取请求站点的 url
【发布时间】:2015-05-03 18:48:56
【问题描述】:

我正在编写一个带有金字塔的小应用程序。一个视图使用 FileResponse 提供文件。我想做的是将这些文件限制在某些域中。

如果此站点http://www.example.com/index.html 包含如下文件:

<img src="http://myapp.com/servethisfile" />

我想知道从我的应用程序请求文件的站点的域。 (example.com)

限制必须在视图内完成,就好像在运行时会发生变化一样。

【问题讨论】:

    标签: python httprequest pyramid


    【解决方案1】:

    浏览器在执行请求时会在 HTTP 标头中发送引荐来源网址。虽然它很容易被破解,但我不会依赖它来保护重要的东西。

    在 Pyramid 中,您可以在 request.referrer 中访问该标头。

    http://docs.pylonsproject.org/projects/pyramid/en/latest/api/request.html#pyramid.request.Request.referer

    【讨论】:

    • 是的,有效。我想提一点,因为我必须自己找出来。如果 request.referrer 和 request.url 相同(referrer 是应用程序本身),则 request.referrer 设置为 None。
    猜你喜欢
    • 1970-01-01
    • 2020-01-15
    • 1970-01-01
    • 2013-03-13
    • 2021-03-21
    • 1970-01-01
    • 2012-06-09
    • 2021-09-06
    • 1970-01-01
    相关资源
    最近更新 更多