user13658830
user13658830

Reputation:

Reset password link on Django website not working

I have a django website. It has sign up and login functionality for users. It's currently hosted on digital ocean. I am using the gmail smtp server to send mails from the contact form and for reset password. But the reset link sent in the email is not working. When I'm running the localhost, the link works but not when hosted on digitalocean. What could be wrong? Here is my urls.py file's code:

from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url
from profiles import views
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.auth import views as auth_views
from django.shortcuts import render
from detail.views import user_login as login_view
from detail.views import user_logout as logout_view


def administrator(request):
    return render(request, 'admin_index.html')


urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('profiles.urls')),
    path('administrator/', administrator),
    path('', include('detail.urls')),
    path('accounts/', include('django.contrib.auth.urls')),
    path('login', login_view, name='user_login'),


     # Password reset links (ref: https://github.com/django/django/blob/master/django/contrib/auth/views.py)
             # ------------------- password change paths -------------

    path('password_change/done/', auth_views.PasswordChangeDoneView.as_view(template_name='registration/password_change_done.html'),
        name='password_change_complete'),

    path('password_change/', auth_views.PasswordChangeView.as_view(template_name='registration/password_change.html'),
        name='password_change'),

        # ------------------- password reset paths -------------

    path('password_reset/done/', auth_views.PasswordResetCompleteView.as_view(template_name='registration/password_reset_done.html'),
     name='password_reset_done'),

    path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(template_name='registration/password_reset_confirm.html'), name='password_reset_confirm'),

    path('password_reset/', auth_views.PasswordResetView.as_view(template_name='registration/password_reset_form.html'), name='password_reset'),

    path('reset/done/', auth_views.PasswordResetCompleteView.as_view(template_name='registration/password_reset_complete.html'),
     name='password_reset_complete'),

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

The password change part also works fine. Thanks

Upvotes: 0

Views: 2083

Answers (2)

Anoop K George
Anoop K George

Reputation: 1735

I have a similar project with working urls, you can refer if you like

I uses session authentication and you can configure templates.

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'),

Upvotes: 2

Anoop K George
Anoop K George

Reputation: 1735

The Gmail prevents access from less secured programs or devices, that why you gets Internal server error 500. When you request reset password the Gmail server responds with error and your Django code may not be configured to handle error catching.

Try following 1. Disable two step verification in Gmail. 2.In Gmail settings, enable less secure app permission to true

Mostly above things works and your password reset function will work but after some time Gmail prevent your python code from accessing its server considering security. Better use your own domain email for all this activities.

Upvotes: 0

Related Questions