Showing `Method Not Allowed (GET): /users/logout/`

Method Not Allowed (GET): /users/logout/
Method Not Allowed: /users/logout/
[10/Dec/2023 12:46:21] "GET /users/logout/ HTTP/1.1" 405 0

This is happening when I went to url http://127.0.0.1:8000/users/logout/

Context: I picked the users app from a different project and did all adjustments to fit my project, but this started showing out of nowhere.

1 Like

See Django 4.1 release notes | Django documentation | Django and Deprecation of GET method for LogoutView

4 Likes

you need to use post request, ie

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

source:

2 Likes

So how to implement the solution ?

Answered in the post immediately above yours.

not really, as the issue came up when visiting the url directly, so its not clear where to implement your solution

You don’t / can’t visit the URL directly. That’s not appropriate any more.

(Well, I guess you could create a view that issues a POST to the logout view, but then you’re circumventing the issues fixed by this change.)