python - 使用 send_mail() [Python - Django] 发送的邮件不发送嵌入图像

标签 python html django email

好的,以下是我的电子邮件模板:

<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/

相关文章:

python - 使用迭代用户输入附加列表,然后将列表索引添加到一起

python - Flask URL 路由

html - 为什么我不能在不调整大小的情况下设置图像的最大宽度

html - 将文本框大小调整为与表格大小相等

html - 表单不在 DIV 中(适用于 IE 9 但不适用于 Chrome 或 IE11)

django - 从 Redis (Django) 中删除 session

python - 列表理解与重复计算

django - 更改 Django 管理中日期字段的默认小部件

python - 如何使用 html 和 css 在 python 中连续显示 3 个帖子?它现在显示最后一个帖子下的每个帖子

python - 在 numpy 数组中查找与特定条件匹配的所有坐标对的最 Pythonic 方法是什么?