send mail to user for password_reset

2019-09-10 15:45发布

问题:

I am trying to implement password_reset (message sending to user for reset his password), but after writing email, nothing has send and the user is redirected to home...

My view.py :

...

from django.contrib.auth.views import password_reset, password_reset_confirm

# Import the render shortcut to render the templates in response.
from django.shortcuts import render

# This view handles the password reset form URL /.
def reset(request):
    return password_reset(request, template_name='le_site/reset.html',
    email_template_name='le_site/password_reset_email.html',
    subject_template_name='le_site/mdp-oublie_texte.txt ',
    post_reset_redirect=reverse('success'))

# This view handles password reset confirmation links. See urls.py file for the mapping.
# This view is not used here because the password reset emails with confirmation links
# cannot be sent from this application.
def reset_confirm(request, uidb64=None, token=None):
    return password_reset_confirm(request, template_name='le_site/password_reset_confirm.html',
    uidb36=uidb36, token=token, post_reset_redirect=reverse('success'))

# This view renders a page with success message.
def success(request):
  return render(request, "le_site/password_reset_complete.html")

...

My urls.py :

from mysite.views import reset
...
url(r'reset$', 'reset', name='reset'), 
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
        'reset_confirm', name='password_reset_confirm'),
url(r'^success/$', 'success', name='success'),
...

I know it's not important but I write directly http://localhost:8000/reset for access to the reset form page.

Why It doesn't works ? :( Why nothing is sent ? Why I am redirect to home page ?

Thank's