I am a beginner in Django and i have been following an online tutorial to build a web application. I had been trying to add the password reset functionality to the application for the past few days. I set up a google app password and finally got the password reset to work. But now, every time i try to reset a password, i receive 2 password reset emails on my email account. I have reset the password successfully a few times but i continue to receive two emails every time i try to reset a password. I tried to look for answers online but couldn't find anything. I have also cross-checked my code with the tutorial. Here are some code snippets that might be relevant:
Project settings.py:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')
Project urls.py:
from django.contrib import admin
from django.urls import path, include
from users import views as user_views
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('register/', user_views.register, name='register'),
path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
path('password-reset/', auth_views.PasswordResetView.as_view(template_name='users/password_reset.html'),
name='password_reset'),
path('password-reset/done/', auth_views.PasswordResetDoneView.as_view(
template_name='users/password_reset_done.html'), name='password_reset_done'),
path('password-reset-confirm/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(
template_name='users/password_reset_confirm.html'), name='password_reset_confirm'),
path('password-reset-complete/', auth_views.PasswordResetCompleteView.as_view(
template_name='users/password_reset_complete.html'), name='password_reset_complete'),
path('profile/', user_views.profile, name='profile'),
path('', include('blog.urls')),
]
Any help will be highly appreciated. Thanks!
PS: This is my first question on StackOverflow. Please let me know if i can improve it in any way.
I had the same problem, but the answer is really simple:
I bet you have 2 Django accounts which use the same mail address. In my case I have a normal user account but I'm also the administrator of Django and use the same mail address for the admin account too. :)
Django loops through all accounts and send a mail to every user where the mail address matches.