Serving static files via https in pyramid

佐手、 提交于 2021-01-27 19:05:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!