0

我正在尝试使 Django 的“静态”标签在所有模板中都可用。我试过这个建议

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'

我究竟做错了什么?

谢谢

4

2 回答 2

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',
)
于 2012-10-07T07:47:14.620 回答
0

问题在这里得到了回答

于 2014-07-30T12:29:11.620 回答