为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 loader.render_to_string 中发送变量以在 html 中显示它

如何在 loader.render_to_string 中发送变量以在 html 中显示它

慕森卡 2021-07-20 17:00:11
我有一个发送电子邮件的函数,我想发送一个要显示在 HTML 电子邮件模板文件中的变量:我的 django 视图:     id=2     html = loader.render_to_string(template,id)     part2 = MIMEText(html, 'html')     msg.attach(part2)
查看完整描述

1 回答

?
临摹微笑

TA贡献1982条经验 获得超2个赞

render_to_string接受context作为第二个参数。像这样使用它:

html = loader.render_to_string(template, {'id': id})


查看完整回答
反对 回复 2021-07-21
  • 1 回答
  • 0 关注
  • 201 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信