Python Django';s html电子邮件';s内联css不起作用
我正在尝试通过HTML电子邮件发送邮件。一切都很正常,但是html文件的内联css并没有在实际的电子邮件中呈现出来。 视图.pyPython Django';s html电子邮件';s内联css不起作用,python,django,django-email,Python,Django,Django Email,我正在尝试通过HTML电子邮件发送邮件。一切都很正常,但是html文件的内联css并没有在实际的电子邮件中呈现出来。 视图.py subject = 'Activate Your Account.' htmly = get_template('account_activation_email.html') d = { 'user': user, 'domain':current_site.domain, 'uid':urlsafe_bas
subject = 'Activate Your Account.'
htmly = get_template('account_activation_email.html')
d = { 'user': user, 'domain':current_site.domain, 'uid':urlsafe_base64_encode(force_bytes(user.pk)), 'token': account_activation_token.make_token(user)}
text_content = ""
html_content = htmly.render(d)
msg = EmailMultiAlternatives(subject, text_content, '', [user.email])
msg.attach_alternative(html_content, "text/html")
try:
msg.send()
except BadHeaderError:
print("Error while sending email!")
这里是我的html文件:
<html>
<head>
</head>
<body>
<div style="backgound-color:red;position:relative;width:100%;text-align:center;">Email Verification</div>
Hi {{ user.username }},
</body>
电子邮件验证
你好{{user.username},
请帮忙 由于拼写:
backgound color
vsbackground color
而跳过红色背景
您是否也尝试过不同的电子邮件客户端—HTML电子邮件本身就是一门艺术。您所写的似乎更多是关于HTML而不是python的,因为django所做的只是呈现其中的变量,它不会更改任何HTML代码。你到底是如何通过电子邮件发送的?我用代码更新了问题。