Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Password Reset Multiple

Hello I am trying to create password reset view in Django. I have set up the mail backend and urls and templates. Everything looks fine but when I try to send mail to reset password Django is sending multiple emails. For example 7 or 11 password reset email at the same time. How can I make it just one email for each time.

Thanks a lot

This is What I did:

setting.py:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST_USER = "my_email"
EMAIL_HOST_PASSWORD = "my_password"
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

urls.py

path('password-reset/',
     auth_views.PasswordResetView.as_view(template_name='accounts/password_reset.html'),
     name='password_reset'),
path('password-reset/done/',
     auth_views.PasswordResetDoneView.as_view(template_name='accounts/password_reset_done.html'),
     name='password_reset_done'),
path('password-set-confirm/<uidb64>/<token>/',
     auth_views.PasswordResetConfirmView.as_view(template_name='accounts/password_reset_confirm.html'),
     name='password_reset_confirm'),
path('password-set-complete/',
     auth_views.PasswordResetCompleteView.as_view(template_name='accounts/password_reset_complete.html'),
     name='password_reset_complete'),

Also, I set the templates for each view.

like image 564
tamurfirat.py Avatar asked Dec 10 '22 03:12

tamurfirat.py


2 Answers

IF this is still a problem... If you have multiple "test users" and you created them with the same email address that is probably causing your problme

like image 194
mancuss Avatar answered Dec 21 '22 17:12

mancuss


It sometimes helps to check the Django source code itself, so always dive into that if you don't understand what's happening.

If you look at PasswordResetForm's save() method in django.contrib.auth.forms, you'll see that it loops through self.get_users(email) and then sends one (and only one) email for each user.

So the only way multiple emails can be sent is if there are multiple users with the same email.

like image 33
dirkgroten Avatar answered Dec 21 '22 16:12

dirkgroten