httphttpsstaticpyramidurl-scheme

Serving static files via https in pyramid


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!


Solution

  • 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