基于Django的html渲染

2019-06-13  本文已影响0人  7ming

问题描述:

想借用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)
完美
上一篇 下一篇

猜你喜欢

热点阅读