我有一个发送电子邮件的功能,我想发送一个要显示在HTML电子邮件模板文件中的变量: 我的django视图:
id=2
html = loader.render_to_string(template,id)
part2 = MIMEText(html, 'html')
msg.attach(part2)
答案 0 :(得分:2)
render_to_string
接受context
作为第二个参数。像这样使用它:
html = loader.render_to_string(template, {'id': id})