在金字塔中通过 https 提供静态文件

Serving static files via https in pyramid

我想通过 request.static_url('some_file') 在金字塔中提供静态文件。由于多项服务,我的模板有如下行:

<script type="text/javascript" src="${request.static_url('dbas:static/first')}"></script>
<script type="text/javascript" src="${request.static_url('websocket:static/second')}"></script>

但不幸的是,方法 static_url() 只提供 http 的链接作为 url_scheme,但我想要 https.我怎样才能做到这一点?

谢谢!

很简单,你只需要指定你想要的方案,例如:

<script type="text/javascript" src="${request.static_url('dbas:static/first', _scheme='https')}"></script>

注意:您也可以指定_host 或_port 来定义url。欲了解更多信息 http://docs.pylonsproject.org/projects/pyramid/en/latest/api/request.html#pyramid.request.Request.route_url

您可以像这样将 url_scheme 参数添加到您的配置文件(由环境分隔):

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6500
url_scheme = https