Search code examples
pythondjangodjango-templatesdjango-urlsdjango-settings

Django reset password email not sent


I'm using default django for reset my user password. Strange thing is i can send email in my code, i receive them. BUT only for the reset password from django i never receive email ...

My django version is Django==3.1.2

Django settings:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER ='****@gmail.com'
EMAIL_HOST_PASSWORD = '*****'

My django URL :

path('password_reset/', auth_views.PasswordResetView.as_view(), name='password_reset'),
path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
path('reset/done/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),

The HTML :

 <form class="form">
 {% csrf_token %}
 {{ form.as_p }}
  <div class="form-group">
      <button type="submit" class="btn btn-pill btn-outline-white font-weight-bold opacity-90 px-15 py-3 m-2">Reset</button>
   </div>
   </form>

When i click on reset button the URL of the page changed to : http://localhost:8000/password_reset/?csrfmiddlewaretoken=MY_TOKEN&email=*******%40hotmail.com

And server send : enter image description here

I can send email using django shell, it's working. I also tried to check if user has is_active True and if user has usable password:

[(u.email, u.is_active, u.has_usable_password()) for u in get_user_model().objects.all()]

I got :

[('******', True, True), ('****', True, True), ('****', True, True), ('*****', True, True)]

Solution

  • You need to make a POST request, so:

    <form class="form" method="post">
        …
    </form>