Python 3.x Django html模板如何在变量中显示变量?
我有templater,它包含。Python 3.x Django html模板如何在变量中显示变量?,python-3.x,django,django-templates,Python 3.x,Django,Django Templates,我有templater,它包含。Driver、Car和campaign模型,我有template base模型,其中所有的模型和正文、文本和另一个字段都包含,我在正文{Driver.fleet}中添加了这些内容,但当我试图查看html模板时,它的fleet值并不是shwoing,而是显示{Driver.fleet}像这样 <section class="table_driver" style="margin: 0 auto; max-w
Driver
、Car
和campaign
模型,我有template base模型,其中所有的模型和正文、文本和另一个字段都包含,我在正文{Driver.fleet}
中添加了这些内容,但当我试图查看html模板时,它的fleet值并不是shwoing,而是显示{Driver.fleet}
像这样
<section class="table_driver" style="margin: 0 auto; max-width: 760px;">
<div class="somehtinff_fix">
{{template.container_en|safe}} #this is fiels
</div>
</section>
这是模板文件所在的代码
ctx = {
"driver": self.driver, # `here is driver and i want to get driver data inside container_ text`
"template": self.template,
"body": self.body,
}
tpl = "email_template.html"
html_message = render_to_string(tpl, ctx)
if self.email:
try:
send_mail(
subject=self.title,
message="",
html_message=html_message,
from_email="DigitalFleet <contact@.io>",
recipient_list=[self.email],
)
ctx={
“driver”:self.driver,#`这是driver,我想在容器文本中获取驱动程序数据`
“模板”:self.template,
“身体”:自我身体,
}
tpl=“email\u template.html”
html\u message=render\u to\u字符串(tpl、ctx)
如果self.email:
尝试:
寄信(
主题=self.title,
message=“”,
html\u message=html\u message,
从\u email=“DigitalFleet”,
收件人列表=[self.email],
)
ctx = {
"driver": self.driver, # `here is driver and i want to get driver data inside container_ text`
"template": self.template,
"body": self.body,
}
tpl = "email_template.html"
html_message = render_to_string(tpl, ctx)
if self.email:
try:
send_mail(
subject=self.title,
message="",
html_message=html_message,
from_email="DigitalFleet <contact@.io>",
recipient_list=[self.email],
)