convert from django 3 to django 5: logout page not works

hi all, I have a code written in django3 and I would like convert it in django5

when I login as user it works in django3 and django5 but when I logout in django3 it redirect to home page while the same code using django5 not go to homepage but error

Method Not Allowed (GET): /logout
Method Not Allowed: /logout
"GET /logout HTTP/1.1" 405 0

the urls.py have the following lines

from django.contrib.auth.views import LoginView,LogoutView
...
path('logout', LogoutView.as_view(template_name='mysite/index.html'),name='logout'),

can someone help me? what’s wrong from django3 to django5?

When upgrading, it’s a good idea to go through the deprecations in the release notes of the versions you’ll be upgrading through. In this case, logging out via HTTP GET was deprecated in Django 4.1:

The built-in logout view now requires HTTP POST instead.

thank you very much…
so i need change line

<a href="/logout" class="nav-item nav-link">Logout</a>

in html codes correct? I have to use form correct?

That’s correct. There’s an example of the form you need at the link above.

It looks like you’re using Bootstrap for CSS? If so you can replace the CSS suggested at the Django docs link for the button, and instead give it an attribute like class="btn btn-link" to maintain the appearance of the existing link.