Skip to content

Commit 04b0d7f

Browse files
authored
Warn against trailing slashes in router prefixes in documentation (#9861)
1 parent 3eb6e55 commit 04b0d7f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

docs/api-guide/viewsets.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ If we need to, we can bind this viewset into two separate views, like so:
4848
user_list = UserViewSet.as_view({'get': 'list'})
4949
user_detail = UserViewSet.as_view({'get': 'retrieve'})
5050

51-
Typically we wouldn't do this, but would instead register the viewset with a router, and allow the urlconf to be automatically generated.
51+
!!! warning
52+
Do not use `.as_view()` with `@action` methods. It bypasses router setup and may ignore action settings like `permission_classes`. Use `DefaultRouter` for actions.
53+
54+
55+
Typically, we wouldn't do this, but would instead register the viewset with a router, and allow the urlconf to be automatically generated.
5256

5357
from myapp.views import UserViewSet
5458
from rest_framework.routers import DefaultRouter
@@ -58,7 +62,7 @@ Typically we wouldn't do this, but would instead register the viewset with a rou
5862
urlpatterns = router.urls
5963

6064
!!! warning
61-
Do not use `.as_view()` with `@action` methods. It bypasses router setup and may ignore action settings like `permission_classes`. Use `DefaultRouter` for actions.
65+
When registering viewsets, do not include a trailing slash in the prefix (e.g., use `r'users'`, not `r'users/'`). Unlike standard Django URL patterns, DRF routers append slashes automatically based on your trailing slash configuration.
6266

6367
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:
6468

0 commit comments

Comments
 (0)