Quantcast
Viewing all articles
Browse latest Browse all 14155

Trouble with Django Authentication: Instead of showing templates it show admin page

I'm currently learning Django authentication and have encountered an issue with customizing HTML templates. Instead of displaying my custom templates, Django redirects me to the admin dashboard.

For instance, when I modify LOGOUT_REDIRECT_URL to logout and name in TemplateView to logout, I expect to see my custom logout page located at templates/registration/logout.html. However, Django continues to redirect me to the default admin dashboard logout page. But when i set both to customlogout then it directs me correctly.

Similarly, I face a problem with the "Forgotten your password?" button. When clicking on it, I anticipate being directed to templates/registration/password_reset_form.html, but instead, I'm redirected to the Django admin dashboard.

Below is my code setup:

settings.py:

LOGIN_REDIRECT_URL = 'home'LOGOUT_REDIRECT_URL = "customlogout"

app urls.py:

from django.urls import pathfrom django.views.generic import TemplateViewurlpatterns = [    path('', TemplateView.as_view(template_name='home.html'), name='home'),     path('logout/', TemplateView.as_view(template_name='logout.html'), name='customlogout'), ]

project urls.py:

from django.contrib import adminfrom django.urls import path, includeurlpatterns = [    path('admin/', admin.site.urls),    path('', include('account.urls')),    path("accounts/", include("django.contrib.auth.urls")), ]

Password reset template templates/registration/password_reset_form.html:

<h1>Password Reset</h1><p>Enter your email ID to reset the password</p><form method="post">    {% csrf_token %}    {{ form.as_p }}<button type="submit">Reset</button></form>

Edit
If I move my templates out of registration folder into templates folder, then the following work

 path('logout/', auth_views.LogoutView.as_view(template_name='logout.html'), name='logout'),    path('password-reset/', auth_views.PasswordResetView.as_view(template_name='password_reset_form.html'), name='password_reset'),

But why its not working before


Viewing all articles
Browse latest Browse all 14155

Trending Articles