2016-11-09 76 views
2

我想通过request.static_url('some_file')在金字塔中提供静态文件。由于一些服务,我的模板了线,如:在金字塔中通过https服务静态文件

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

谢谢!

+0

退房这太问题http://stackoverflow.com/questions/39033106/pyramid- debug-toolbar-serving-static-content-over-http-instead-of-https –

+0

谢谢,但我现在想要通过https:\ –

回答

1

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

<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

+0

进行每次调用。但是在开发中,我使用http和生产https。 –

+1

您可以传递setup.ini中定义的环境变量(例如,development.ini和production.ini),如myproject.scheme = http并传递给模板以使其变为像settings.get('myproject.scheme ')'http')) –

2

您可以url_scheme PARAM添加到您的配置文件(由环境中分离出来)这样的:

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

不知道为什么这是downvoted,这是正确的,每个wsgi文档在这里:https://wsgi.readthedocs.io/en/latest/definitions.html#wsgi-environ-keys –

+0

是@ Jonno_FTW,我不知道为什么它也被低估了。 –