我有一个模特:
class DocumentoPaziente(models.Model):
nome = models.CharField(null=True, blank=True, max_length=50)
cognome = models.CharField(null=True, blank=True, max_length=50)
contenuto = models.CharField(null=True, blank=True, max_length=100000)
变量内容:
Il Paziente <font color="#000000"><font face="Arial, serif"><font size="3" style="font-size: 12pt"><span lang="zxx"><b>{{ member.cognome }}
{{ member.nome }}</b></span></font><font color="#000000"><font face="Arial, serif"><font size="3" style="font-size: 12pt"><span lang="zxx">
abitante [...]
在模板中:
{% autoescape off %}
{{ member.contenuto }}
{% endautoescape %}
它呈现
Il Paziente {{ member.cognome }} {{ member.nome }} abitante [...]
预期:
Il Paziente Smith John abitante [...]
答案 0 :(得分:0)
您可以在模型中定义一个函数以正确进行渲染,例如:
from django.template import Template, Context
class DocumentoPaziente(models.Model):
nome = models.CharField(null=True, blank=True, max_length=50)
cognome = models.CharField(null=True, blank=True, max_length=50)
contenuto = models.CharField(null=True, blank=True, max_length=100000)
def render_content(self):
return Template(self.contuento).render(Context({'member': self}))
然后,您可以在模板中使用以下内容呈现该图片:
{% autoescape off %}
{{ member.render_content }}
{% endautoescape %}