【发布时间】:2012-02-18 15:27:00
【问题描述】:
我正在构建一个应用程序,它使用 Django 模板引擎/语言来“编译”一些 HTML。但是,该应用程序不能在 Django 上运行,并且没有所有的配置和东西。 当我尝试使用它时,我收到以下错误:
Traceback (most recent call last):
File "Send.py", line 33, in <module>
template = loader.get_template("email.html")
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 157, in get_template
template, origin = find_template(template_name)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 138, in find_template
raise TemplateDoesNotExist(name)
django.template.base.TemplateDoesNotExist: email.html
我使用的代码如下:
from django.template import loader, Context
from django.conf import settings
template = loader.get_template("email.html")
rendered = template.render(data)
模板与 Python 文件位于同一目录中。
【问题讨论】:
-
这是一个适用于 Django >= 1.8 stackoverflow.com/a/34494931/817277 的答案