作者:新起点新娘妆 | 来源:互联网 | 2023-09-05 09:10
IvebuiltamenuasatemplatetaginDjango>1.9.Theproblemisthatfollowingthissolution,I
I've built a menu
as a templatetag
in Django>1.9. The problem is that following this solution, I can't put the templatetag at the root of the folder, as I'm getting a:
我在Django> 1.9中构建了一个菜单作为模板标签。问题是,遵循这个解决方案,我不能把模板标签放在文件夹的根目录,因为我得到一个:
TemplateSyntaxError: 'menu' is not a registered tag library
TemplateSyntaxError:'menu'不是已注册的标记库
Below is the part of my settings.py
that I've modified:
以下是我修改过的settings.py的一部分:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# Look for base template at root of project
'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',
],
# Look for base templatetags at root of project
'libraries': {
'project_tags': 'templatetags.menu',
}
},
},
]
Even with an empty menu.py
template tag like the one below I get the same error:
即使有一个像下面那样的空menu.py模板标签,我也会得到同样的错误:
from django import template
register = template.Library()
@register.inclusion_tag('menu.html', takes_cOntext=True)
def menu(context):
pass
Does Django
support project-wide templatetags
at all?
Django是否支持项目范围的模板标签?
1 个解决方案