Django Get absolute url for static files

前端 未结 6 640
孤独总比滥情好
孤独总比滥情好 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:17

    Not entirely sure what you're asking, but since the {% static .. %} is only adding /static/ to the front of your path you specify, you could just do that yourself:

    {{ request.build_absolute_uri }}static/img/myimage.jpg
    

    Not very modular, but then again most times you don't need direct access to the full url since it will just append it onto whatever url you're at if you use it as a src for some html object.

提交回复
热议问题