Home > Back-end >  Django reset password get Server Error 500 when deployed to production in Azure
Django reset password get Server Error 500 when deployed to production in Azure

Time:04-11

I'm trying to implement a reset password feature in my Django app using django.contrib.auth` like this:


from django.urls import path
from .import views
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('', views.index, name='index'),
    path("login", views.login_view, name="login"),
    path("logout", views.logout_view, name="logout"),
    path('register', views.register, name='register'),
    path('admin_main', views.admin_main, name='admin_main'),
    path('admin_csv', views.admin_csv, name='admin_csv'),
    path('admin_pdf', views.admin_pdf, name='admin_pdf'),

    path('reset_password/', auth_views.PasswordResetView.as_view(), name="reset_password"),
    path('reset_password_sent/', auth_views.PasswordResetDoneView.as_view(), name="password_reset_done"),
    path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(), name="password_reset_confirm"),
    path('reset_password_complete/', auth_views.PasswordResetCompleteView.as_view(), name="password_reset_complete"),
]

if settings.DEBUG:
    urlpatterns  = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Everything works just fine during development but in production (Azure App Service) when I introduce the email to reset the password and submit the form, I get "Server Error (500)" and the reset password mail is not send, any idea why could this be?

Also, the rest of the web modules are working correctly in production, DEBUG mode is off and ALLOWED_HOST is set.

The SMTP configuration is as follows:


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

CodePudding user response:

Is the reset_password/ the only endpoint that returns 500? Perhaps you have to set ALLOW_HOSTS?

CodePudding user response:

I think I found the solution I went on this link https://accounts.google.com/DisplayUnlockCaptcha and clicked on Continue. After that it started working.

  • Related