mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
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.
This commit is contained in:
parent
56e4508123
commit
606df83885
|
@ -59,7 +59,7 @@ using the `APIView` class-based views.
|
|||
}
|
||||
return Response(content)
|
||||
|
||||
Or, if you're using the `@api_view` decorator with function based views.
|
||||
If you're using the `@api_view` decorator with function based views you can use the following decorator.
|
||||
|
||||
@api_view(['GET'])
|
||||
@throttle_classes([UserRateThrottle])
|
||||
|
@ -69,6 +69,16 @@ Or, if you're using the `@api_view` decorator with function based views.
|
|||
}
|
||||
return Response(content)
|
||||
|
||||
It's also possible to set throttle classes for routes that are created using the `@action` decorator.
|
||||
Throttle classes set in this way will override any viewset level class settings.
|
||||
|
||||
@action(detail=True, methods=["post"], throttle_classes=[UserRateThrottle])
|
||||
def example_adhoc_method(request, pk=None):
|
||||
content = {
|
||||
'status': 'request was permitted'
|
||||
}
|
||||
return Response(content)
|
||||
|
||||
## How clients are identified
|
||||
|
||||
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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user