Skip to content

Commit 606df83

Browse files
authored
Update throttling.md (#7606)
There were recent updates to the `@action` decorator calling a little more attention to the kwargs it accepts. I thought it would be useful to also provide an example in the throttling section of how those kwargs can be used to define/override throttle_classes through the action decorator as well.
1 parent 56e4508 commit 606df83

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

docs/api-guide/throttling.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ using the `APIView` class-based views.
5959
}
6060
return Response(content)
6161

62-
Or, if you're using the `@api_view` decorator with function based views.
62+
If you're using the `@api_view` decorator with function based views you can use the following decorator.
6363

6464
@api_view(['GET'])
6565
@throttle_classes([UserRateThrottle])
@@ -69,6 +69,16 @@ Or, if you're using the `@api_view` decorator with function based views.
6969
}
7070
return Response(content)
7171

72+
It's also possible to set throttle classes for routes that are created using the `@action` decorator.
73+
Throttle classes set in this way will override any viewset level class settings.
74+
75+
@action(detail=True, methods=["post"], throttle_classes=[UserRateThrottle])
76+
def example_adhoc_method(request, pk=None):
77+
content = {
78+
'status': 'request was permitted'
79+
}
80+
return Response(content)
81+
7282
## How clients are identified
7383

7484
The `X-Forwarded-For` HTTP header and `REMOTE_ADDR` WSGI variable are used to uniquely identify client IP addresses for throttling. If the `X-Forwarded-For` header is present then it will be used, otherwise the value of the `REMOTE_ADDR` variable from the WSGI environment will be used.

0 commit comments

Comments
 (0)