问题描述:
想借用Django 的 template.render函数生成html文件,但是又不想建立Django项目
解决
from django.template import Template, Context
from django.template.engine import Engine
from django.conf import settings
settings.configure(DEBUG=False)
template_string = "Hello {{ name }} and how are you"
template = Template(template_string, engine=Engine())
context = Context({"name": "world"})
output = template.render(context)
print(output)
网友评论