我创建了一个电子邮件模板在html即时消息发送电子邮件使用下面的看法,这是工作良好。但当我收到电子邮件时,它是以原始html格式显示的。我可以知道是什么错误吗。你知道吗
def confirmed_email_notification(sender, **kwargs):
"""
Sends an email notification to the shop owner when a new order is
completed.
"""
print "EMAIL NOTIFICATION "
subject_template_name = 'shop_simplenotifications/confirmed_subject.txt'
body_template_name = 'shop_simplenotifications/confirmed_body.html'
request = kwargs.get('request')
order = kwargs.get('order')
subject = loader.render_to_string(
subject_template_name,
RequestContext(request, {'order': order})
)
subject = subject.join(subject.splitlines())
body = loader.render_to_string(
body_template_name,
RequestContext(request, {'order': order})
)
from_email = getattr(settings, 'SN_FROM_EMAIL',
settings.DEFAULT_FROM_EMAIL)
owners = getattr(settings, 'SN_OWNERS', settings.ADMINS)
send_mail(subject, body, from_email,
[owner[1] for owner in owners], fail_silently=False)
print body
print [owner[1] for owner in owners]
confirmed.connect(confirmed_email_notification)
如果您使用的是django1.7,那么可以将消息的html版本作为
html_message
参数cfhttps://docs.djangoproject.com/en/1.7/topics/email/#send-mail传递给send_mail()
否则您可以使用
EmailMultiAlternatives
类,如下所述: https://docs.djangoproject.com/en/1.6/topics/email/#sending-alternative-content-types或者使用
EmailMessage
类并将content_subtype
属性设置为“html”。你知道吗顺便说一句:我真的很怀疑
subject.join(subject.splitlines())
做你想做的事:相关问题 更多 >
编程相关推荐