是否可以通过 django rest 框架中的节流 类 获取接收到的请求数量?
Is it possible to get number of how many requests were received via throttling classes in django rest framework?
如标题所述,是否可以通过 django rest 框架中的节流 类 获取接收到的请求数量?有关更多信息,对于限制 类 我使用 UserRateThrottle,对于身份验证 类 我使用 TokenAuthentication,对于权限 类 我使用 IsAuthenticated。我只能获得限制数量,例如 1000/天。我确实尝试在 google 上找到解决方案,但我运气不好!谢谢!
并非开箱即用,但您可以自己轻松实施解决方案。
UserRateThrottle
is a subclass of SimpleRateThrottle
, which contains methods throttle_success
and throttle_failure
您可以重新实现两者并添加您自己的日志记录逻辑、在缓存中存储计数器或通过
进行其他操作
def throttle_success(self):
log.info("throttle success")
# alternatively, increment a counter somewhere
# call super implementation
super().throttle_success()
如标题所述,是否可以通过 django rest 框架中的节流 类 获取接收到的请求数量?有关更多信息,对于限制 类 我使用 UserRateThrottle,对于身份验证 类 我使用 TokenAuthentication,对于权限 类 我使用 IsAuthenticated。我只能获得限制数量,例如 1000/天。我确实尝试在 google 上找到解决方案,但我运气不好!谢谢!
并非开箱即用,但您可以自己轻松实施解决方案。
UserRateThrottle
is a subclass of SimpleRateThrottle
, which contains methods throttle_success
and throttle_failure
您可以重新实现两者并添加您自己的日志记录逻辑、在缓存中存储计数器或通过
进行其他操作def throttle_success(self):
log.info("throttle success")
# alternatively, increment a counter somewhere
# call super implementation
super().throttle_success()