-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rest_framework.urls doesn't work with LogoutView in Django 5.0 #9206
Comments
can you share the traceback as well please? |
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 |
As a workaround until this gets fixed, I added logout view manually: class LogoutView(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]
def get(self, request):
logout(request)
return redirect('/') then in
|
As a side-note to this fix, make sure you put the url pattern before you include e.g.
|
should we need some documentation updated? |
Workaround: from django.contrib.auth.views import LogoutView
class PatchLogoutView(LogoutView):
http_method_names = ["get", "post", "options"]
def get(self, request, *args, **kwargs):
return self.post(request, *args, **kwargs) Then on urls path("api-auth/logout/", PatchLogoutView.as_view(), name="logout"),
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")), |
anyone up for contribution? |
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 |
If it is already implemented in main branch then what should we need to change actually? |
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. |
thanks. |
Hi can someone please help? Logout page is still not working url: urlpatterns = [ views: |
In Django 5.0, GET request for logout was removed (only POST supported now) and it seems like in DRF we still do GET request to the endpoint.
https://docs.djangoproject.com/en/5.0/releases/5.0/
The text was updated successfully, but these errors were encountered: