django +发送电子邮件在html与django注册 [英] django+ send email in html with django-registration

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

问题描述

im使用django注册,一切正常,确认电子邮件是以纯文本发送,但知道我已经修复,并发送在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 ...

任何想法?

谢谢

推荐答案

p>我建议发送文本版本和html版本。查看django注册的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 - 替代内容类型

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 +发送电子邮件在html与django注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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