【问题标题】:Serving static files via https in pyramid在金字塔中通过 https 提供静态文件
【发布时间】:2017-03-23 10:28:28
【问题描述】:

我想通过 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。我怎样才能做到这一点?

谢谢!

【问题讨论】:

标签: http https static pyramid url-scheme


【解决方案1】:

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

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

【讨论】:

【解决方案2】:

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

<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

【讨论】:

  • 但在开发中我使用的是 http,而在生产中使用的是 https。
  • 您可以传递在 setup.ini 中定义的环境变量(例如 development.ini 和 production.ini),例如 myproject.scheme = http 并传递给模板以使其像(设置.get('myproject.scheme', 'http'))
猜你喜欢
  • 1970-01-01
  • 2019-02-22
  • 2011-10-20
  • 1970-01-01
  • 2013-09-18
  • 1970-01-01
  • 2014-05-17
  • 1970-01-01
  • 2011-01-27
相关资源
最近更新 更多