我正在构建一个应用程序,它使用 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 文件位于同一目录中。
最佳答案
我建议使用 Jinja2而不是 Django 模板作为独立的解决方案。
关于python - 在没有 Django 其余部分的情况下使用 Django 的模板引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9002826/