seting配置
REST_FRAMEWORK = {
....
'DEFAULT_THROTTLE_CLASSES': (
'rest_framework.throttling.AnonRateThrottle',
'rest_framework.throttling.UserRateThrottle'
),
'DEFAULT_THROTTLE_RATES': {
'anon': '3/min',
'user': '10000/day'
}
}
自定义
class CustomThrottle(SimpleRateThrottle):
scope = 'foo'
def get_cache_key(self, request, view):
pass