You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rest_framework.urls doesn't work with LogoutView in Django 5.0 #9206
As a workaround until this gets fixed, I added logout view manually:
classLogoutView(APIView):
""" Djano 5 does not have GET logout route anymore, so Django Rest Framework UI can't log out. This is a workaround until Django Rest Framework implements POST logout. Details: https://github.com/encode/django-rest-framework/issues/9206 """permission_classes= [permissions.IsAuthenticated]
defget(self, request):
logout(request)
returnredirect('/')
As a workaround until this gets fixed, I added logout view manually:
classLogoutView(APIView):
""" Djano 5 does not have GET logout route anymore, so Django Rest Framework UI can't log out. This is a workaround until Django Rest Framework implements POST logout. Details: https://github.com/encode/django-rest-framework/issues/9206 """permission_classes= [permissions.IsAuthenticated]
defget(self, request):
logout(request)
returnredirect('/')
Hi can someone please help? Logout page is still not working
url:
from django.contrib import admin
from django.urls import path,include
from .views import Index,SignUpView,PatchLogoutView
from django.contrib.auth import views as auth_views
from rest_framework import routers, serializers, viewsets
Activity
auvipy commentedon Jan 3, 2024
can you share the traceback as well please?
meaniebeanie22 commentedon Jan 5, 2024
Is there any way to bypass this in the mean time? I updated my django version to 5.0 and as such can't find a way to logout
Scorpil commentedon Feb 16, 2024
@meaniebeanie22
As a workaround until this gets fixed, I added logout view manually:
then in
urls.pyadd it to urlpatterns:MichaelGatesDev commentedon Feb 28, 2024
As a side-note to this fix, make sure you put the url pattern before you include
rest_framework.urls(if you are doing so) otherwise it will not work.e.g.
auvipy commentedon Feb 28, 2024
should we need some documentation updated?
gaurovsoni commentedon Mar 4, 2024
Workaround:
Then on urls
auvipy commentedon Mar 5, 2024
anyone up for contribution?
TGoddessana commentedon Mar 5, 2024
hello. What can I do? I'd like to contribute.
Can I just modify the view corresponding to the api-auth url? It looks like already implemented in main branch. @auvipy
auvipy commentedon Mar 5, 2024
If it is already implemented in main branch then what should we need to change actually?
gaurovsoni commentedon Mar 5, 2024
I don't think there is a need to change anything now. since it's already merged #9208 . Just waiting for official djangorestframework package update.
auvipy commentedon Mar 5, 2024
thanks.
joeisone commentedon May 12, 2024
Hi can someone please help? Logout page is still not working
url:
from django.contrib import admin
from django.urls import path,include
from .views import Index,SignUpView,PatchLogoutView
from django.contrib.auth import views as auth_views
from rest_framework import routers, serializers, viewsets
urlpatterns = [
path('',Index.as_view(),name='index'),
path('signup/',SignUpView.as_view(),name='signup'),
path('login/', auth_views.LoginView.as_view(template_name='inventory/login.html'),name='login'),
path("api-auth/logout/", PatchLogoutView.as_view(), name='logout'),
path('api-auth/', include('rest_framework.urls',namespace="rest_framework")),
views:
class PatchLogoutView(LogoutView):
http_method_names = ["get", "post", "options"]
def get(self, request, *args, **kwargs):
return self.post(request, *args, **kwargs)