遇到报错django.template.exceptions.TemplateSyntaxError: ‘staticfiles’ is not a registered tag library. Must
ROOT_URLCONF = ''
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',
},
},
},
]
解决办法参考链接:https://www.cnblogs.com/yizhipanghu/p/15346297.html
html 模版中新增一个图片
<div id="title">
<div><img src="{% static "imgs/stu04.jpg" %}"></div>
<div>学生信息</div>
</div>
#STATICFILES_DIRS --- 全局变量定义了存储静态文件集合
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
os.path.join(BASE_DIR, 'abc'),
os.path.join(BASE_DIR, 'app01', 'static')
]