python - 在没有 Django 其余部分的情况下使用 Django 的模板引擎

标签 python django templates

我正在构建一个应用程序,它使用 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/

相关文章:

Python seaborn plot 将数据名称显示为 ㅁㅁㅁㅁ。我怎样才能解决这个问题?

python - 在 Django 管理中为每个项目显示图标

c++ - 模板化运算符<<显式实例化和 header

c++ - 在嵌套模板中使用类成员指针会导致 GCC 错误 "mismatched types Child and Base"

python - 如何知道安装的pylab版本?

python - 具有历史记录的唯一观看次数

python - Pandas:访问行号

django - 如何在ckeditor中配置简单的链接和图像附加?

python - 单元测试 JWT token 过期 : Django REST

c++ - 对 C++ 嵌套依赖类型名称感到困惑