报错如下:

解决方法:
在settings.py加上
'libraries': { # Adding this section should work around the issue.
'staticfiles': 'django.templatetags.static'}
加上之后如下,即可成功访问了~
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],
'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',
],
'libraries': { # Adding this section should work around the issue.
'staticfiles': 'django.templatetags.static',
},
},
},
]
本文介绍了在遇到Django报错TemplateSyntaxError: 'staticfiles' is not a registered tag library时的解决方法,只需在settings.py中进行简单配置即可解决问题。
617

被折叠的 条评论
为什么被折叠?



