I want to use django buildin LogoutView library but it is not working. When i use this, it shows "This page isn’t working" The logout function should work and logout the user. Below is the urls.py code.
from django.urls import path
from .views import TaskList, TaskDetail, TaskCreate, TaskUpdate, DeleteView, CustomLoginView, RegisterPage, TaskReorder
from django.contrib.auth.views import LogoutView
urlpatterns = [
path('login/', CustomLoginView.as_view(), name='login'),
path('logout/', LogoutView.as_view(next_page='login'), name='logout'),
path('register/', RegisterPage.as_view(), name='register'),
path('', TaskList.as_view(), name='tasks'),
path('task/<int:pk>/', TaskDetail.as_view(), name='task'),
path('task-create/', TaskCreate.as_view(), name='task-create'),
path('task-update/<int:pk>/', TaskUpdate.as_view(), name='task-update'),
path('task-delete/<int:pk>/', DeleteView.as_view(), name='task-delete'),
path('task-reorder/', TaskReorder.as_view(), name='task-reorder'),
]
The problem is not the view, the problem is how you make the request. Logging out is a state-changing request, you should not do that with a GET request, since that violates the HTTP protocol. Therefore, since django-5.0, it has to be done through a POST request, with a mini-form:
<form method="post" action="{% url 'logout' %}">
{% csrf_token %}
<button type="submit">logout</button>
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With