【发布时间】:2019-08-13 17:06:21
【问题描述】:
我正在使用 jinja2 在 django 中渲染模板:
模板设置:
TEMPLATES = [
{
"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",
]
},
},
{"BACKEND": "django.template.backends.jinja2.Jinja2", "DIRS": ["utils/"]},
]
调用代码:
html_template = get_template("email/contact/contact.html") #completes successfully - template definitely found
html_message = render_to_string(html_template, context)
这给出了错误:
AttributeError: 'Template' object has no attribute 'split'
谷歌搜索仅显示以下解决方案:
AttributeError: 'NoneType' 对象没有属性 'split'
这表明找不到模板。这不是这里的情况。
【问题讨论】:
标签: django django-templates jinja2