What is the difference between {% load staticfiles %} and {% load static %}

前端 未结 5 1629
说谎
说谎 2020-12-07 18:52

The most important part of the question is in the topic.

I am wondering what tag is best for which case. Moreover... I found code, that also use settings.STATI

5条回答
  •  死守一世寂寞
    2020-12-07 19:10

    Refer to the docs, where there is a nice explanation of it. Actually the {% static %} template tag know the location of STATICFILE_STORAGE

    As docs say :

     {% load static from staticfiles %} Hi! The previous example is equal to calling the url method of an instance of STATICFILES_STORAGE with "images/hi.jpg".
    

    This is especially useful when using a non-local storage backend to deploy files as documented in Serving static files from a cloud service or CDN.

    If you’d like to retrieve a static URL without displaying it, you can use a slightly different call:

    {% load static from staticfiles %}
    {% static "images/hi.jpg" as myphoto %}
    Hi!
    

    Hope that helps!!

提交回复
热议问题