Hi, here is my running code:
path(‘logout/’,auth_views.LogoutView.as_view(template_name=“pages/logout.html”, next_page=‘/’), name=‘logout’),
Here is my problem:
Method Not Allowed (GET): /logout/
Method Not Allowed: /logout/
[30/Apr/2024 00:58:54] “GET /logout/ HTTP/1.1” 405 0
I already read some solutions avaiable, I tried to create a mini-form and link to that, but it wasn’t avaiable.
Here is my mini-form:
logout.html
<form method="post" action="{% url 'logout' %}">
{% csrf_token %}
<button type="submit">logout</button>
</form>
Please help me, thanks a lot!
That form should be in the page containing your logout link, that’s not the logout template to be rendered by the logout view. (In other words wherever you have a link to “logout”, that’s where this form would be defined.)
Hi, I don’t understand your answer, can you explain more clearly please ?
So should I changed the template_name variable to the normal path, the put the logout.html file in other path ?
I actually found a way to fix the error:
path('logout/', LogoutView.as_view(next_page='register/', http_method_names = ['get', 'post', 'options']), name='logout'),
But now what I get is the Django administration logging out message going out, no matter how I changed the next_page variable. Please show me how to fix this message
1 Like
You have to put this mini-form in a page that contain your logout button… and don’t use template name only next_page
That’s the wrong “fix”. You’ve just undone the security fix implemented by this change.
You have a Logout
link on some page(s), that currently directs you to the logout
url.
That link is what gets replaced by the mini form.
For us to be more specific, we’d need to see the template containing the Logout
link.