我正在构建一个解决方案,其中我有一个核心API,我已经根据官方文档https://www.django-rest-framework.org/api-guide/throttling/
实现了节流。但我想知道我怎样才能monitor the requests so that no genuine user of the app gets blocked and if so should be able to unblock it.
我的设置.py文件
REST_FRAMEWORK = {
'DEFAULT_THROTTLE_CLASSES': (
'rest_framework.throttling.ScopedRateThrottle',
),
'DEFAULT_THROTTLE_RATES': {
'students': '1/minute',
}
}
还有我的视图.py你知道吗
class StudentViewSet(viewsets.ModelViewSet):
throttle_scope = 'students'
Django REST框架提供的throttle类不允许这样做。您必须创建一个定制的throttle类并覆盖
allow_request()
来记录节流事件,并提供一些用于白名单的工具。例如,类似这样的事情:如何最好地实现白名单和日志记录取决于您的具体需求。你知道吗
相关问题 更多 >
编程相关推荐