问题
i want to serve static files in pyramids via request.static_url('some_file'). Due to several services, my templates got lines like:
<script type="text/javascript" src="${request.static_url('dbas:static/first')}"></script>
<script type="text/javascript" src="${request.static_url('websocket:static/second')}"></script>
But unfortunately the method static_url() only delivers links with http as url_scheme, but i want https. How can I achieve this?
Thanks!
回答1:
Easy, you only need to specify the scheme you want, for example:
<script type="text/javascript" src="${request.static_url('dbas:static/first', _scheme='https')}"></script>
Note: You can also specify _host or _port to define the url. For more info http://docs.pylonsproject.org/projects/pyramid/en/latest/api/request.html#pyramid.request.Request.route_url
回答2:
You can add url_scheme param to your configuration file (separated by environment) like that:
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6500
url_scheme = https
来源:https://stackoverflow.com/questions/40509902/serving-static-files-via-https-in-pyramid