Django 无法显示提供的注销模板

Django unable to display the logout template provided

我有以下问题;我正在尝试使用默认 contrib.auth 视图设置用户登录和注销,但显示的注销页面是 django admin 的默认页面,而登录页面没有问题并显示我提供的支持模板

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 %)

显示的注销页面是django admin的默认页面,而登录页面没有问题,显示的是我提供的支持模板

class 默认查看 registration/logged_out.html 文件,但是,您也可以提供自定义位置:

path("logout/", 
     auth_views.LogoutView.as_view(template_name="accounts/logout.html"),
     name="logout"),