For the moment (Django 1.9 and earlier), {% load staticfiles %}
loads the static
templatetag from the contrib app that has more features than the built-in django.core.static
.
The most important difference is staticfiles
can manage files stored on CDN, since its resolver can manage hashes for example. core.static
only append STATIC_URL
to the static filename, which is not enough if you're processing your files (e.g. adding md5 hash to clear cache between releases)
This difference is due to the fact that managing non-local storage files was not dedicated to be included in the core package of Django, but was still useful to many developers to be implemented as a official contrib package. So if you started to use staticfiles
, you had to remember to use it every in your templates. BUT, some problems could appear, for example when using Media
classes so the decision has been to merge those two templatetags into one and use a different behaviour whether the developer has django.contrib.staticfiles
in its INSTALLED_APPS
or not.
From Django 1.10 and onwards (also see ticket in Django tracker), the {% load static %}
is going to use staticfiles
internally if activated (oherwise keep default behaviour), and the templatetag in the contrib package will be deprecated to avoid confusion.
TL;DR
- Before Django 1.10:
staticfiles
loads a templatetags that can manage non-local storage where static
can't (or not easily) ;
- From Django 1.10:
contrib.staticfiles
app still exist but its templatetags will be removed only the {% static %}
templatetags remains ;
- From Django 2.0 (I believe):
{% load staticfiles %}
is removed.
For now, use staticfiles
templatetags if you use the related contrib app (and you know why you are using it) until Django 1.10, otherwise just use static
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…