我正在使用jinja2在django中渲染模板:
TEMPLATES = [
{
"BACKEND": "django.template.backends.jinja2.Jinja2",
"DIRS": [os.path.join(BASE_DIR, "templates/jinja2/")],
"APP_DIRS": True,
"OPTIONS": {"environment": "management.jinja2_conf.environment"},
},
{
"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",
]
},
},
]
初始模板位于myproject/foo/templates/jinja2/...
中。 Jinja似乎觉得很好。该模板扩展了myproject/templates/jinja2/...
中的基本模板。找不到这个。奇怪的是,根据模板加载器事后分析,当django搜索基本模板时,它不使用jinja2-它仅使用通常的django后端。我不知道为什么会这样...
验尸:
Template loader postmortem
Django tried loading these templates, in this order:
Using engine django:
* django.template.loaders.app_directories.Loader: /Users/foo/.pyenv/versions/management/lib/python3.7/site-packages/django/contrib/admin/templates/base_email.plain (Source does not exist)
* django.template.loaders.app_directories.Loader: /Users/foo/.pyenv/versions/management/lib/python3.7/site-packages/django/contrib/auth/templates/base_email.plain (Source does not exist)
* django.template.loaders.app_directories.Loader: /Users/foo/.pyenv/versions/management/lib/python3.7/site-packages/rest_framework/templates/base_email.plain (Source does not exist)
* django.template.loaders.app_directories.Loader: /Users/foo/work/sva/management/users/templates/base_email.plain (Source does not exist)
* django.template.loaders.app_directories.Loader: /Users/foo/work/sva/management/utils/templates/base_email.plain (Source does not exist)