From 199e5a931796cc048c03225e17ab040ba8298080 Mon Sep 17 00:00:00 2001 From: Mahdi Date: Tue, 11 Nov 2025 14:41:27 +0330 Subject: [PATCH 1/2] Add warning for .as_view() with @action. Fixes #9638 --- docs/api-guide/viewsets.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/api-guide/viewsets.md b/docs/api-guide/viewsets.md index 22acfe327a..5550c3ceda 100644 --- a/docs/api-guide/viewsets.md +++ b/docs/api-guide/viewsets.md @@ -57,6 +57,8 @@ Typically we wouldn't do this, but would instead register the viewset with a rou router.register(r'users', UserViewSet, basename='user') urlpatterns = router.urls +> **Warning**: Do not use `.as_view()` with `@action` methods. It bypasses router setup and may ignore action settings like `permission_classes`. Use `DefaultRouter` for actions. + Rather than writing your own viewsets, you'll often want to use the existing base classes that provide a default set of behavior. For example: class UserViewSet(viewsets.ModelViewSet): From 8e059483b2d640853739d4d93ce0e5dd13f22015 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Tue, 9 Dec 2025 08:54:03 +0000 Subject: [PATCH 2/2] Update warning to use consistent syntax --- docs/api-guide/viewsets.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api-guide/viewsets.md b/docs/api-guide/viewsets.md index 5550c3ceda..bb42a097a6 100644 --- a/docs/api-guide/viewsets.md +++ b/docs/api-guide/viewsets.md @@ -57,7 +57,7 @@ Typically we wouldn't do this, but would instead register the viewset with a rou router.register(r'users', UserViewSet, basename='user') urlpatterns = router.urls -> **Warning**: Do not use `.as_view()` with `@action` methods. It bypasses router setup and may ignore action settings like `permission_classes`. Use `DefaultRouter` for actions. +**Warning**: Do not use `.as_view()` with `@action` methods. It bypasses router setup and may ignore action settings like `permission_classes`. Use `DefaultRouter` for actions. Rather than writing your own viewsets, you'll often want to use the existing base classes that provide a default set of behavior. For example: