我已将django-registration的部分内容克隆到我的项目中。具体来说,RegistrationProfile
位用于生成activation_key,用户激活和验证电子邮件发送。
我已使用EmailMultiAlternatives版本替换了本机send_email位以发送HTML电子邮件。
它看起来像这样:
def send_activation_email(self, site):
context = {
'link': (site+"signup/activate/"+self.activation_key),
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
'site': site
}
# SUBJECT
subject = render_to_string(
'registration/activation_email_subject.txt',
context
)
subject = ''.join(subject.splitlines())
# BODY
html_content = render_to_string(
'registration/activation_email.html',
context
)
text_content = strip_tags(html_content)
# MESSAGE
message = EmailMultiAlternatives(
subject,
text_content,
settings.DEFAULT_FROM_EMAIL,
[self.user.email]
)
message.attach_alternative(html_content, "text/html")
我可以在模板中打印{{link}}
的链接。如果我想要<a href={{link}}>Activate</a>
(或按钮)之类的内容,如何将链接用作href属性?