2016-11-09 40 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,我不知道爲什麼它也被低估了。 –