django 1.7.8 not sending emails with password reset
OK, it's most likely something failing in the forms clean method, and you aren't trapping that error. So you just get the redirect without sending the mail, and no clue as to why. Any validation error thrown in clean() will show up in non_field_errors. You need to add in {{form.non_field_errors}} into your page to see them. Try this:
<form method="post">{% csrf_token %}
{{{form.non_field_errors}}
{{ form.email.errors }}
<p><label for="id_email">E-mail address:</label> {{ form.email }} <input type="submit" value="Reset password" /></p>
</form>
When you POST to ^accounts/password/reset/$
the django.contrib.auth.views.password_reset function is run. This will use the default django.contrib.auth.forms.PasswordResetForm class to validate the email.
You should notice that an email is sent only to the active users matching the provided email, and only if they have a usable password.
Try to use the following function with the Django management shell:
from django.contrib.auth.models import get_user_model
def check_password_reset_cond(email):
for u in get_user_model().objects.filter(email__iexact=email):
assert u.is_active
assert u.has_usable_password()
Do you have email templates in your templates
folder ?
registration/password_reset_email.html
registration/password_reset_subject.txt
I tried to recreate your situation and I faced the following scenarios:
- Mail is only sent to active users. Email associated with no user will not get any email(obviously).
- I got an error form's save method in line 270 for
email = loader.render_to_string(email_template_name, c)
:
NoReverseMatch at /accounts/password/reset/ Reverse for 'password_reset_confirm' with arguments '()' and keyword arguments '{'token': '42h-4e68c02f920d69a82fbf', 'uidb64': b'Mg'}' not found. 0 pattern(s) tried: []
It seems that your urls.py doesn't contain any url named 'password_reset_confirm'. So you should change your url:
url(r'^accounts/password/reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
'django.contrib.auth.views.password_reset_confirm',
{'post_reset_redirect': '/accounts/password/done/'},),
To:
url(r'^accounts/password/reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
'django.contrib.auth.views.password_reset_confirm',
{'post_reset_redirect': '/accounts/password/done/'}, name='password_reset_confirm'),
If you have set your email configuration perfectly the you should get emails with no problem. If still you are facing this issue, please use a debugger to check where its getting exceptions.
PS: I have tested with django 1.7.8 and templates resides in: Python34\Lib\site-packages\django\contrib\admin\templates\registration
. Urls and views are used as you have written in the question.