Django Get absolute url for static files
django, python
Solution
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:
<img src="{{request.scheme}}://{{request.META.HTTP_HOST}}{% static 'img/myimage.jpg' %}">
Problem
In Django, when I use: ``` {{ request.build_absolute_uri }}{% static "img/myimage.jpg" %} ``` It produces: 'http://myurl.com//static/img/myimage.jpg'. This produces an error. How can I remove the double slashes? The STATIC URL is: ``` STATIC_URL = '/static/' ``` But I don't think removing the first '/' would be a good idea.