1

I have a Django rest backend that takes data from frontend made in angular, and I've tried throttling the number of requests from the same Ip address to 5 per 10 minutes using ratelimit but was unable to do it.

Since I'm new to this part of drf, I didn't really know what to do to make it work, tried finding/reading posts on how to implement it with ViewSet, but could not figure out how to make it work.

@method_decorator(ratelimit(key = 'ip', rate = '5/10m', block=True), name='dispatch')
class ContactViewSet(viewsets.ModelViewSet):
    queryset = Contact.objects.all()
    serializer_class = ContactSerializer

    def dispatch(self, request, *args, **kwargs):
        return super(IndexView, self).dispatch(request, *args, **kwargs)

After sending 5 requests it shouldn't allow anymore for 10 minutes.

Thanks in advance.

Eric
  • 57
  • 6

0 Answers0