【发布时间】:2013-08-20 22:17:50
【问题描述】:
在视图代码中渲染模板(例如电子邮件)时,有什么方法可以完全关闭 django auto_escaping:
from django.template import Context, Template
subject_template_string = "Hi {{ customer.name }}"
subject_template = Template(subject)
context = Context({'customer':MyCustomerModel.objects.get(pk=1)})
subject = subject_template.render(context)
如果customer.name 类似于“Jack & Jill” - 主题看起来类似于“Hi Jack &\amp; Jill”(没有反斜杠!)
有没有类似的
subject = subject_template.render(context, autoescape=False)
编辑:实际的模板是由客户端在数据库中创建的,我希望避免在可能发生这种情况的所有模板中添加|safe...
【问题讨论】: