5
django有没有在每个模板的顶部不需要{% load static %}
的方法?在django中加载所有模板的静态文件
This question表示您可以将常见的加载标签分解为设置,但在此情况下不提供所需的详细信息。
django有没有在每个模板的顶部不需要{% load static %}
的方法?在django中加载所有模板的静态文件
This question表示您可以将常见的加载标签分解为设置,但在此情况下不提供所需的详细信息。
由于Django的1.9,你可以添加以下到您的模板设置:
'builtins': ['django.contrib.staticfiles.templatetags.staticfiles']
例如,整个模板设置可能是这样的:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'builtins': [
'django.contrib.staticfiles.templatetags.staticfiles',
],
},
},
]