我正在尝试在所有模板中使用Django'静态'标记。我试过this suggestion:
from django.template.loader import add_to_builtins
add_to_builtins('django.contrib.staticfiles') # I've tried each of these
add_to_builtins('django.contrib.staticfiles.templatetags')
add_to_builtins('django.contrib.staticfiles.templatetags.staticfiles')
但是不断收到以下错误消息:
django.template.base.InvalidTemplateLibrary: Template library django.contrib.staticfiles does not have a variable named 'register'
我做错了什么?
由于
答案 0 :(得分:0)
您需要在'django.core.context_processors.static',
中添加settings.py
,如下所示:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.request',
'django.contrib.messages.context_processors.messages',
)
答案 1 :(得分:0)
问题已在SO here
上得到解答