2

I am trying to amend the password rest form from django-registration to include a hyperlink. I used the exact same code for the activation_email.html but it is not working for the password_reset_email.html. The generated email is printing all of the html tags like < p >. What am I missing?

Below is the code for the password_reset_email.html:

{% load i18n %}
<!doctype html>
<html lang="en">

{% blocktrans %}Hello,{% endblocktrans %}

{% blocktrans %}
To reset your password, please click the following link:
{% endblocktrans %}
<body>
    <p> 
        <a href="http://{{site.domain}}{% url 'auth_password_reset_confirm' uid token %}">
            Reset password
        </a>
    </p>
</body>
{% blocktrans %}
If you do not wish to reset your password, please ignore this message.
{% endblocktrans %}

{% blocktrans %}Thanks,{% endblocktrans %}
{% blocktrans %}Management Team{% endblocktrans %}


{# This is used by django.contrib.auth #}

Here is the code for activation_email.html for comparison. This generates the correct result.

{% load i18n %}
<!doctype html>
<html lang="en">

<head>
    <title>{{ site.name }} {% trans "registration" %}</title>
</head>

<body>
<p>
    {% blocktrans with site_name=site.name %}
    Hello!
</p>

<p>
    We're ready to activate your account. All we need to do is make sure this is your email address.
    {% endblocktrans %}
</p>    

<p> 
    <a href="http://{{site.domain}}{% url 'registration_activate' activation_key %}">
        Confirm email
    </a>
</p>
<p>
    {% blocktrans %}
    If you didn't create a account, please just delete this email.
    {% endblocktrans %}

</p>
</body>

</html>
H C
  • 1,138
  • 4
  • 21
  • 39

1 Answers1

0

Sounds like the email is being sent as text. Make sure with whatever method you are using that you are sending as html.

If you are using send_mail from django.core.mail, then you need to provide the html_message parameter in addition to message.

sponrad
  • 680
  • 6
  • 9
  • I think django-registration maybe uses the django default password template. (again documentation on how form.email works). Is there a place I should specify this? – H C Nov 16 '15 at 22:19
  • I just got what you mean. I change my url to this. Is this what you intended? url(r'^password/reset/$', auth_views.password_reset, {'html_email_template_name': 'registration/password_reset_email.html', 'post_reset_redirect': reverse_lazy('auth_password_reset_done')}, name='auth_password_reset'), – H C Nov 16 '15 at 22:38
  • Now the html email isn't picking up {{site.domain}}. Do you know how one might fix that? – H C Nov 16 '15 at 22:43
  • Actually it looks like django-registration does not natively support html emails by default: https://django-registration.readthedocs.org/en/master/quickstart.html#required-templates You may need to modify it's model like in this answer: http://stackoverflow.com/questions/1325983/django-send-email-in-html-with-django-registration site.domain may need to be explicitly set in the view and passed to the template if it is not picking it up. You can extend any of the built in views to do that. – sponrad Nov 16 '15 at 23:20
  • Thank you very much for your help. The strange thing is that the activation email is already sent as an html (as my html for activation works above). However, the password reset seems to be using some default django template that I can't see the documentation. What should I do in this case? I didn't define and views or forms to be able to modify. – H C Nov 16 '15 at 23:29
  • That sounds strange, I don't think there is a default password templates, they are usually provided by you under some folder like `/registration`. That template has to be somewhere in your project. – sponrad Nov 16 '15 at 23:40
  • Under django.contrib.auth, there is a default password reset form, in fact a whole suite. (This is what I have been able to debug to but not sure what the next step is.) I'm not sure if I should just copy the code and modify it or put in some arguments/settings to change it's behavior. – H C Nov 16 '15 at 23:42