aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide
diff options
context:
space:
mode:
authorTom Christie2014-12-19 16:09:01 +0000
committerTom Christie2014-12-19 16:09:01 +0000
commitd109ae0a2e78551977d93e2507267e43a685fafd (patch)
tree156c3d6d999e43c145fcf2da35ec1413c61ae083 /docs/api-guide
parent80bacc5fb00682b589b3280c7082af73e3aaa8f8 (diff)
parent8f0fef4b75f5c999c13b5d37a263da3a3388142e (diff)
downloaddjango-rest-framework-d109ae0a2e78551977d93e2507267e43a685fafd.tar.bz2
Merge pull request #2010 from tanwanirahul/master
Ability to customize method names without creating a custom router
Diffstat (limited to 'docs/api-guide')
-rw-r--r--docs/api-guide/routers.md18
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/api-guide/routers.md b/docs/api-guide/routers.md
index 929a1710..6819adb6 100644
--- a/docs/api-guide/routers.md
+++ b/docs/api-guide/routers.md
@@ -68,6 +68,24 @@ The following URL pattern would additionally be generated:
* URL pattern: `^users/{pk}/set_password/$` Name: `'user-set-password'`
+If you do not want to use the default URL generated for your custom action, you can instead use the url_path parameter to customize it.
+
+For example, if you want to change the URL for our custom action to `^users/{pk}/change-password/$`, you could write:
+
+ from myapp.permissions import IsAdminOrIsSelf
+ from rest_framework.decorators import detail_route
+
+ class UserViewSet(ModelViewSet):
+ ...
+
+ @detail_route(methods=['post'], permission_classes=[IsAdminOrIsSelf], url_path='change-password')
+ def set_password(self, request, pk=None):
+ ...
+
+The above example would now generate the following URL pattern:
+
+* URL pattern: `^users/{pk}/change-password/$` Name: `'user-change-password'`
+
For more information see the viewset documentation on [marking extra actions for routing][route-decorators].
# API Guide