开发者

How to make Django template engine to render in memory templates?

开发者 https://www.devze.com 2022-12-20 15:42 出处:网络
I am开发者_开发技巧 storing my templates in the database and I don\'t have any path to provide for the template.render method.

I am开发者_开发技巧 storing my templates in the database and I don't have any path to provide for the template.render method.

Is there any exposed method which accepts the template as a string?

Is there any workaround?


Based on the the docs for using the template system:

from django.template import Template, Context

t = Template("My name is {{ my_name }}.")
c = Context({"my_name": "Adrian"})
t.render(c)


Instantiate Template with the string to use as a template.


In Django < 1.8:

from django.template.loader import get_template_from_string

tpl = Template(get_template_from_string("My name is {{ my_name }}."))
0

精彩评论

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