Mik*_*keN 3 python django django-templates
我已经为我的用户构建了一种基于Django模板语言的宏语言.用户在UITextFields中输入可以在较大文档的上下文中呈现的模板/宏片段.所以我有django模板代码的大型多行字符串片段,应该使用也存储在内存中的变量填充.我不想将任何东西转储到文件中,我需要渲染这些模板
如何在存储在内存中的字符串(在python实例变量中)的模板上调用Django模板渲染器?应该填充该模板的变量也是存储在内存中的实例变量.
from django.template import Context, Template
template = Template("this is a template string! {{ foo }}")
c = Context({"foo": "barbarbar"})
print template.render(c)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
366 次 |
| 最近记录: |