django - Python发送一封电子邮件,将变量值传递给html
问题描述
在我的项目中,我必须发送一封电子邮件并将一个值传递给 html 代码。我试试这个:
l_sender = []
l_sender.append('mario.rossi@test.com')
emailsend(l_sender)
def emailsend(l_sender):
context = {
'news': 'We have good news!'
}
try:
send_html_email(l_sender, 'Get started with Aida', 'email.html', context, sender='wepredict@cathedral.ai')
print("Email send")
except Exception as e:
print(e)
在 email.html 我插入 {{ context.news }} 但什么也没发生。如何在 mail.html 中传递我的新闻 val 值?
提前致谢
解决方案
为什么是 context.news?您必须使用{{ news }}
. 您调用的函数甚至看不到您的变量已命名context
。
看看这个例子:用 Django 创建电子邮件模板
推荐阅读
- rest - 如何通过 REST API 在锯齿组中创建地址
- php - 我的 Joomla 网站显示 PHP 错误:无法打开流
- sql - 为什么要将整个记录存储在审计表中?
- xaml - 无法在传递参数的 XAML 命令中绑定我的 Converter 类
- java - 如何在大型 SQL 数据库上实现实时搜索/搜索视图
- c++ - 用数组打印空心正方形
- javascript - ReactJs 项目
- java - 如何以编程方式检查电话号码是否存在?
- sql-server-2008 - SQL Server 更改表查询未按预期工作
- python - 无法使用安装了 ubuntu、numpy、opencv 的方式编写 dockerfile