Deprecation of GET method for LogoutView

I was just wondering why the logout is not working after updating Django and have seen that using GET method is deprecated while using django.contrib.auth.views.LogoutView. What’s the point behind the decision to deprecate GET method?

Maybe someone can enlighten me to understand why I cannot use a simple logout via <a href> in combination with the default LogoutView because it feels like I’m missing something really important why POST is much better than GET in this case.

The short answer is that it’s basically “un safe” for the user.

The Django developers mailing list has a couple of threads as to why this was considered appropriate.

1 Like

Am new to Django currently having this issue, my logout is always returning “GET /accounts/logout/ HTTP/1.1” 405 0, and am using CBV

<form method="post" action="{% url 'logout' %}">
    {% csrf_token %}
    <button type="submit">logout</button>

This work for me but i need to customize the template for the logout user who is not an admin

<form method="post" action="{% url 'logout' %}">
    {% csrf_token %}
    <button type="submit">logout</button>

Side note: When you’re posting code or templates here, you need to surround the text between lines of three backtick - ` characters. This means you’ll have a line of ```, then the code (or template), then another line of ```. (I’ve taken the liberty of modifying your posts for this, please remember to do this in the future.)

So you know what it is you need to do - what is it that you have questions about?


Hi! I put the same form in templates, but still I see the same issue. Can you give me more information about all of the steps that you executed connected to the Log out?

Hello i have the same problem do you found a solution?

The answer is at Deprecation of GET method for LogoutView - #5 by kemoNjie, which is the same answer as in the other thread here that you found.

1 Like

Ok I see, but with the default authentication system there is no need to write views or URLs right all I have to do is write the templates but in this case how knowing that normally I am supposed to enter the hard URL in the browser to log out the user . In this case, how to make sure to display the suggested logout form in the solution

hey iam also new to django
my solution is try using the button enclosed by form with POST method and use csrf token

<form method="post" action="{% url 'logout' %}">
    {% csrf_token %}
    <button type="submit">logout</button>

{% else %}

<a href="{% url 'login' %}">login</a>
{%  endif %}

Hi @shivamalk-23,

The code you have mentioned is not working for me, I am getting the same error.

Pls help me with this,

Welcome @prudviraj939 !

You’re going to need to be a lot more specific here.

When & how are you using this? What are you doing (specifically) when the error is being thrown? What is the exact error being received?

1 Like

Hi @KenWhitesell,

Thanks for the reply

I am trying to create a Logout view using the below code,

from django.contrib.auth.views import LoginView, LogoutView

class LogoutInterfaceView(LogoutView):
template_name = ‘home/logout.html’

and I have also added url path in in the app home,
path(‘login’, views.LoginInterfaceView.as_view(), name=“login”),
path(‘logout’, views.LogoutInterfaceView.as_view(), name=“logout”)

When I am tryig to access logout endpoint, I am getting this error
Method Not Allowed (GET): /logout
Method Not Allowed: /logout
[27/Feb/2024 17:26:06] “GET /logout HTTP/1.1” 405 0

pls help me through this?

You cannot go directly to /admin/logout/ as a url using a get.

You post:

How are you trying to access this? What link are you clicking on a page to do this?

Hi @KenWhitesell,

Sorry for the wrong output I have posted. I have changed it over there. I have tried various suggestions mentioned in this thread. Nothing is working. Pls help me through this.

You still need to specifically identify what it is that you are doing that is creating that output. If you’re clicking a link on a page, you need to show the html from the page containing that link. If you’re doing something else to send a request to that URL, you need to show what you’re doing.

1 Like

This is the HTML I am using for logout.html,

So you’re saying that you’re clicking on this button, and that is creating the error that you’re seeing?

It would be a lot more helpful to see the rendered HTML as it exists in the browser for the page containing the link being clicked.

1 Like

This is the HTML that have been rendered, I have already posted template I am using and view I have built using it