Complete the code to import the throttle class for rate limiting in Django REST Framework.
from rest_framework.throttling import [1]
The UserRateThrottle class is used to apply rate limiting per user in Django REST Framework.
Complete the code to set the throttle classes in a Django REST Framework view.
class MyView(APIView): throttle_classes = [[1]]
The throttle_classes attribute expects throttle classes like UserRateThrottle to limit request rates.
Fix the error in the throttle rate setting in Django REST Framework settings.
"DEFAULT_THROTTLE_RATES": { "user": "[1]" }
The throttle rate must be a string with a number and a time unit separated by a slash, like '100/hour'.
Fill both blanks to create a custom throttle class that limits requests to 10 per minute.
from rest_framework.throttling import [1] class CustomThrottle([2]): rate = '10/minute'
Custom throttles usually inherit from SimpleRateThrottle to define a custom rate. The import should be SimpleRateThrottle since the class inherits from it.
Fill all three blanks to apply throttling globally in Django REST Framework settings.
REST_FRAMEWORK = {
'DEFAULT_THROTTLE_CLASSES': [
'[1]',
],
'DEFAULT_THROTTLE_RATES': {
'[2]': '[3]'
}
}To enable throttling globally, set DEFAULT_THROTTLE_CLASSES to the full path of the throttle class, and define DEFAULT_THROTTLE_RATES with the key matching the throttle scope and the rate string.