Django: is not a registered tag library.
阿新 • • 發佈:2018-12-07
http://blog.51cto.com/zhangrf/2107991
自定義模板標籤,使用時報以下錯誤
TemplateSyntaxError at /my_customer_tags/
'admin_tags' is not a registered tag library. Must be one of:
admin_list
admin_modify
admin_static
admin_urls
cache
custom_tags
i18n
kingadmin_tags
l10n
log
static
staticfiles
tz
解決方法:
在proj.settings中做如下設定
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',
'app.apptemplates.load_setting',
],
'libraries':{
'my_customer_tags': 'yourapp.templatetags.my_customer_tags',
}
},
},
]