I have the following problem; Im trying to set up user login and logout using the default contrib.auth views but the logout page that is displayed is the default page of django admin while the login page has no problem and displays the support template that I have provided it
django-tutorial/urls.py
from django.contrib import admin
from django.conf.urls.static import static
from django.urls import path, include
from django.conf import settings
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('landingpage.urls')),
path('articles/', include('articles.urls')),
path('accounts/', include('accounts.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
accounts/urls.py
from django.urls import path
from django.contrib.auth import views as auth_views
app_name = 'accounts'
urlpatterns = [
path('login/', auth_views.LoginView.as_view(), name='login'),
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
path('password_change/', auth_views.PasswordChangeView.as_view(), name='password_change'),
path('password_change/done/', auth_views.PasswordChangeDoneView.as_view(), name='password_change_done'),
path('password_reset/', auth_views.PasswordResetView, name='password_reset'),
path('password_reset/done/', auth_views.PasswordResetDoneView, name='password_reset_done'),
path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
path('reset/done/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
]
login.html
{% extends "landingpage/base.html" %}
{% block page_content %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
{% if next %}
{% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed,
please login with an account that has access.</p>
{% else %}
<p>Please login to see this page.</p>
{% endif %}
{% endif %}
<form method="post" action="{% url 'accounts:login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="submit" value="login">
<input type="hidden" name="next" value="{{ next }}">
</form>
{# Assumes you setup the password_reset view in your URLconf #}
<p><a href="{% url 'accounts:password_reset' %}">Lost password?</a></p>
{% endblock %}
logged_out.html
{% extends "landingpage/base.html" %}
{% block page_content %}
<div class="container-fluid p-5">
<h2>Logout</h2>
<br>
<p>Grazie per aver speso del tempo di qualità in questo sito oggi!</p>
<p>Speriamo di rivederti presto</p>
<br>
<a href="{% url 'accounts:login' %}">Vuoi rifare il Login?</a>
</div>
{% endblock %)
the logout page that is displayed is the default page of django admin while the login page has no problem and displays the support template that I have provided it
The class by default looks at registration/logged_out.html
file, however, you can provide custom location too:
path("logout/",
auth_views.LogoutView.as_view(template_name="accounts/logout.html"),
name="logout"),