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

前端 未结 5 1636
说谎
说谎 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:33

    The built-in static template tag "link[s] to static files that are saved in STATIC_ROOT".

    The staticfiles contrib app's static template tag "uses the configured STATICFILES_STORAGE storage to create the full URL for the given relative path", which is "especially useful when using a non-local storage backend to deploy files".

    The built-in static template tag's documentation (linked to above) has a note that says to use the staticfiles contrib app's static template tag "if you have an advanced use case such as using a cloud service to serve static files", and it gives this example of doing so:

    {% load static from staticfiles %}
    Hi!
    

    You could use {% load staticfiles %} rather than {% load static from staticfiles %} if you want, but the latter is more explicit.

提交回复
热议问题