gpt4 book ai didi

python - Pyramid 调试工具栏通过 HTTP 而不是 HTTPS 提供静态内容

转载 作者:行者123 更新时间:2023-11-28 21:45:42 25 4
gpt4 key购买 nike

在我们的测试服务器上,我们使用 Pyramid debug toolbar但是,它会生成指向静态内容(如其 CSS 和 JavaScript 文件)的 http:// 链接,而其余内容则通过 HTTPS 提供。这会导致混合内容警告,并破坏所有功能。有没有办法强制它生成 HTTPS 链接?

我知道可以在 Chrome 中启用混合内容,这很有效,但对于整个 QA 团队来说,这不是一个可行的解决方案。

最佳答案

可能有更好/更简单的方法来实现这一点,但您可以做一件事来实现这一点,即在每次调用 request.static_url() 时添加 _scheme='https' 参数

为此,您当然可以编辑 pyramid/url.py,但您也可以在项目的 __init__.py 中执行此操作:

from pyramid.url import URLMethodsMixin

URLMethodsMixin.static_url_org = URLMethodsMixin.static_url # backup of original

def https_static_url(self, *args, **kw):
kw['_scheme'] = 'https' # add parameter forcing https
return URLMethodsMixin.static_url_org(self, *args, **kw) # call backup

URLMethodsMixin.static_url = https_static_url # replace original with backup

static_url 的参数类似于 route_url .来自文档:

Note that if _scheme is passed as https, and _port is not passed, the _port value is assumed to have been passed as 443. Likewise, if _scheme is passed as http and _port is not passed, the _port value is assumed to have been passed as 80. To avoid this behavior, always explicitly pass _port whenever you pass _scheme. Setting '_scheme' automatically forces port 443

关于python - Pyramid 调试工具栏通过 HTTP 而不是 HTTPS 提供静态内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39033106/

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