diff options
| author | Rahul | 2014-12-19 20:31:21 +0530 | 
|---|---|---|
| committer | Rahul | 2014-12-19 20:31:21 +0530 | 
| commit | 6aa0e307c99d0c17d7c48f2416472c7dbdcbbf8f (patch) | |
| tree | e7dc4b8625dfa5af24410755f881b999ec438db6 | |
| parent | a8a3fedb5c52cc62c6ecf59c4138e9a6ecf04806 (diff) | |
| download | django-rest-framework-6aa0e307c99d0c17d7c48f2416472c7dbdcbbf8f.tar.bz2 | |
Added documentation about url_path parameter for custom actions.
| -rw-r--r-- | docs/api-guide/routers.md | 18 | 
1 files changed, 18 insertions, 0 deletions
| diff --git a/docs/api-guide/routers.md b/docs/api-guide/routers.md index 61a476b8..63b8b59a 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 did not like the default URL generated for your custom action, you could use `url_path` parameter with `@detail_route` or `@list_route` 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): +            ... + +Above example would instead generate 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 | 
