mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 13:00:12 +03:00
DOCS
This commit is contained in:
parent
b4e70dfdbf
commit
7832909926
|
@ -118,6 +118,26 @@ The above example would now generate the following URL pattern:
|
||||||
|
|
||||||
* URL pattern: `^users/{pk}/change-password/$` Name: `'user-change-password'`
|
* URL pattern: `^users/{pk}/change-password/$` Name: `'user-change-password'`
|
||||||
|
|
||||||
|
In the case you do not want to use the default name generated for your custom action, you can use the url_name parameter to customize it.
|
||||||
|
|
||||||
|
For example, if you want to change the name of our custom action to `'user-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_name='change-password')
|
||||||
|
def set_password(self, request, pk=None):
|
||||||
|
...
|
||||||
|
|
||||||
|
The above example would now generate the following URL pattern:
|
||||||
|
|
||||||
|
* URL pattern: `^users/{pk}/set_password/$` Name: `'user-change-password'`
|
||||||
|
|
||||||
|
You can also use url_path and url_name parameters together to obtain extra control on URL generation for custom views.
|
||||||
|
|
||||||
For more information see the viewset documentation on [marking extra actions for routing][route-decorators].
|
For more information see the viewset documentation on [marking extra actions for routing][route-decorators].
|
||||||
|
|
||||||
# API Guide
|
# API Guide
|
||||||
|
|
Loading…
Reference in New Issue
Block a user