0
menu
をDjango> 1.9にtemplatetag
として作成しました。以下は Djangoのすべてのアプリケーションで共通のメニュー
TemplateSyntaxError: 'menu' is not a registered tag library
settings.py
の一部です: 問題は、私は取得していますように、この
solution次、私は、フォルダのルートにtemplatetagを置くことができないということです修正:
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',
}
},
},
]
でも、私は同じエラーを取得以下のような空のmenu.py
テンプレートタグで:
from django import template
register = template.Library()
@register.inclusion_tag('menu.html', takes_context=True)
def menu(context):
pass
を
Django
はプロジェクト全体をサポートしますtemplatetags
?
あなたは "templatetags"フォルダを持っていますか?あるいは、テンプレート内で '{%include" menuTemplate "%}"を使用することもできます... – hansTheFranz
htmlファイルのスニペットを提供できますか? – mateuszb
@hansTheFranz 'menu.py'は、プロジェクトのルートにある' templatetags'フォルダの中にあります。 – h4k1m