Django REST Framework: Check Throttle Limit Remaining Requests
To check how many throttle limits you have left in Django REST Framework, you can use the 'throttle_scope' object provided by the framework.
For example, if you have a view that is throttled by a rate limit of 100 requests per day, you can check how many requests are left by calling the 'throttle_scope' object like this:
from rest_framework.throttling import UserRateThrottle
class MyView(APIView):
throttle_classes = [UserRateThrottle]
def get(self, request):
# Check how many requests are left for this user
remaining_requests = self.throttle_scope.get_remaining_requests(request)
# Return the remaining requests in the response
return Response({'remaining_requests': remaining_requests})
This will return a JSON response with the number of remaining requests for the user.
原文地址: https://www.cveoy.top/t/topic/mUb0 著作权归作者所有。请勿转载和采集!