django+ 使用 django-registration 以 html 格式发送电子邮件 [英] django+ send email in html with django-registration

查看:24
本文介绍了django+ 使用 django-registration 以 html 格式发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 django-registration,一切都很好,确认电子邮件以纯文本形式发送,但我知道我已修复并以 html 发送,但我有一个垃圾问题... html 代码显示:

im using django-registration, all is fine, the confirmation email was sending in plain text, but know im fixed and is sending in html, but i have a litter problem... the html code is showing:

<a href="http://www.example.com/accounts/activate/46656b86eefc490baf4170134429d83068642139/">http://www. example.com/accounts/activate/46656b86eefc490baf4170134429d83068642139/</a>

而且我不需要像...一样显示 html 代码

and i dont need to show the html code like the ...

有什么想法吗?

谢谢

推荐答案

我建议同时发送文本版本和 html 版本.在 django-registration 的 models.py 中查找:

I'd recommend sending both a text version and an html version. Look in the models.py of the django-registration for :

send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [self.user.email])

而是从文档中执行类似操作 http://docs.djangoproject.com/en/dev/topics/email/#sending-alternative-content-types

and instead do something like from the docs http://docs.djangoproject.com/en/dev/topics/email/#sending-alternative-content-types

from django.core.mail import EmailMultiAlternatives

subject, from_email, to = 'hello', 'from@example.com', 'to@example.com'
text_content = 'This is an important message.'
html_content = '<p>This is an <strong>important</strong> message.</p>'
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()

这篇关于django+ 使用 django-registration 以 html 格式发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆