Django Get absolute url for static files

前端 未结 6 680
孤独总比滥情好
孤独总比滥情好 2021-01-07 22:38

In Django, when I use:

{{ request.build_absolute_uri }}{% static \"img/myimage.jpg\" %}

It produces: \'http://myurl.com//static/img/myimage

6条回答
  •  没有蜡笔的小新
    2021-01-07 23:38

    The request object is available within your templates and you can easily access attributes such as request.scheme or request.META.HTTP_HOST to construct your base URL that you can prepend ahead of your static URL to get the full URL.

    Final example would look something like this:

    
    

提交回复
热议问题