好的,以下是我的电子邮件模板:
<html>
<head>
{% load staticfiles %}
</head>
<body>
<h2>Welcome!</h2>
<img src = "{% static 'app/images/logo1.png' %}" style = "position: absolute; left: 5%; height: 100%; width:50%;" />
<div style = "position: absolute; top: 100%; left: 0%; height: 10%; width: 100%: color: #006699;"></div>
<img src = "{% static 'app/images/content.png' %}" style = "position: absolute; left:0%; top: 110%; height: 100%; width: 60%">
</img>
</body>
</html>
以下是我的电子邮件功能:
html_template = render_to_string('email_template.html', {})
try:
send_mail(
'Title',
'Plaintext Version Goes Here',
'sender',
[email],
html_message=html_template,
)
except:
return HttpResponse("No!")
当我发送邮件时仅欢迎!打印在邮件中。图像不显示。知道为什么吗?
提前致谢!
最佳答案
我解决了这个问题,指定了完整的 STATIC_URL,例如 http://localhost:8000/static/ 部署后,我更改为域。 尝试更改为
<img src = "http://localhost:8000/static/app/images/logo1.png" style = "position: absolute; left: 5%; height: 100%; width:50%;" />
我找到了这个possible other solution但我没有尝试过。
关于python - 使用 send_mail() [Python - Django] 发送的邮件不发送嵌入图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32685246/