问题描述
我将模板存储在数据库中,我没有任何路径来提供template.render
方法。
是否有任何接受模板作为字符串的公开方法?
有没有解决方法?
1楼
基于使用模板系统 :
from django.template import Template, Context
t = Template("My name is {{ my_name }}.")
c = Context({"my_name": "Adrian"})
t.render(c)
2楼
用字符串作为模板使用。
3楼
在Django <1.8:
from django.template.loader import get_template_from_string
tpl = Template(get_template_from_string("My name is {{ my_name }}."))