(Django 5.03] problem with django.contrib.auth.views.LogoutView

13 Views Asked by At

Today i am reviving an old django project. After creating all the needed things and importing the database, i could login and it worked (Or so i thought!)

Everything works like it was when i abandoned the project a year or so ago, except the logout link in my header.

enter image description here enter image description here

I looked for people with similar problems and i found this: As per the Django 5.0 release notes, support for logging out via GET requests in the django.contrib.auth.views.LogoutView is removed. You must issue a POST in order to log out and be redirected.

But that doesn't help me at all. I will show some of the code i use below:

header.html

<li class="nav-item ">
                    <a class="nav-link " href="logout "> {{user.username.capitalize}} uitloggen</a>
                </li>

views.py

from django.contrib.auth.models import User, auth

def logout(request):
    auth.logout(request)
    return redirect('/')

urls.py

from django.contrib.auth import views
from members import views as member_views

 path('logout/', views.LogoutView.as_view(template_name='registration/logout.html'), name='logout'),

logout.html

{% extends 'index.html' %}
{% block css %}<meta http-equiv="refresh" content="5;{% url 'index' %}">{% endblock %}
    

{% block title %}Logout{% endblock title %}

{% block content %}
<div class="container bground2">
<div class="form">
<h2>You are logged out</h2>
<h6>You will be redirected to the Home Page</h6>
    <div class="border-top pt-3 pb-5">
        <small class="text-muted text-center">
            Login again<a class="ml-2" href={% url "login" %}>Login</a>
        </small>
    </div>
</div>
</div>
{% endblock content %}

Like i said, it was working before but because they have changed it in Django 5, i have to log out with a POST instead of a GET request. I don't have a clue where to change that GET request into Post I hope someone can help me - based on how it worked before - how to change it for Django 5 so it will work again.

0

There are 0 best solutions below