2

I've cloned parts of django-registration into my project. Specifically, the RegistrationProfile bit for activation_key generation, user activation, and verification email sending. I've replaced the native send_email bit with a EmailMultiAlternatives version to send HTML Emails. It look something like this:

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")

I can print the link with {{link}} in the template. How can I use the link as an href attribute if I wanted something like <a href={{link}}>Activate</a> (or a button)?

4
  • 2
    Does <a href='{{link}}'>Activate</a> work (note quotes)? If I'm correctly understanding the question. Commented Jun 27, 2014 at 20:37
  • I've tried it but my <a></a> tag turn up empty. Commented Jun 27, 2014 at 21:20
  • <a href="{{ link }}">Activate</a> should work. Commented Sep 28, 2016 at 14:50
  • Similar question here Commented Jan 4, 2017 at 13:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.