, Throttled
.
from rest_framework.views import exception_handler
from rest_framework.exceptions import Throttled
def custom_exception_handler(exc, context):
response = exception_handler(exc, context)
if isinstance(exc, Throttled):
custom_response_data = {
'message': 'request limit exceeded',
'availableIn': '%d seconds'%exc.wait
}
response.data = custom_response_data
return response
DRF.
REST_FRAMEWORK = {
'EXCEPTION_HANDLER': 'my_project.my_app.utils.custom_exception_handler'
}
, throttleType
, DRF, DRF Throttled
, - Throttle . Throttled
, throttle_class
.