开发者

Invoke Django template renderer in memory without any files from strings?

I have built a Macro language for my users that is based upon the Django template language. Users enter into UITextFields their template/macro snippets that can be rendered in the context of larger documents. So I have large multi-line string snippets of django template code that should be populated with variables that are also stored in memory. I don't want to ever have to dump anything to files, I need to render these template

How can I invoke the Django template renderer on a template that开发者_C百科 is stored in a string in memory (in python instance variables)? The variables that should populate that template are also instance variables stored in memory.


from django.template import Context, Template

template = Template("this is a template string! {{ foo }}")
c = Context({"foo": "barbarbar"})
print template.render(c)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜