在Django中加载静态模板标记的正确方法是什么?

时间:2015-02-15 14:26:21

标签: django static

文档有点含糊不清......

https://docs.djangoproject.com/en/dev/howto/static-files/#configuring-static-files中说

{% load staticfiles %}

并在https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#template-tags中说

{% load static from staticfiles %}

(我们的一些模板只有{% load static %},虽然我不确定这是否真的有用......?)

1 个答案:

答案 0 :(得分:3)

两种方式都是正确的。但我总是使用{% load staticfiles %}

{% static %}staticfiles库中唯一的标记,因此我没有理由使用{% load static from staticfiles %}版本。

至于{% load static %} - 这是built-in template tag,它与staticfiles contrib app无关。如果您不使用(并且不打算使用)任何特殊的STATICFILES_STORAGE,那么这个版本对您来说就可以了。

相关问题