Understanding Django Throttling

Author: Muhammad AbdulMoiz

Implementing Throttling for rate limitting

Who am I?

Author: Muhammad AbdulMoiz

Muhammad AbdulMoiz
Software Engineer @

Technologies i have worked on

Author: Muhammad AbdulMoiz
Javascript
Angular
Ionic
RxJs
ngRx
KoaJs

Topics

  • Understanding Throttling
    
  • Django Throttling policy
  • Throttle types
  • Dig down in implementation
 

Django Throttling

Throttling

Django Throttling

Setting up the throttle policy

REST_FRAMEWORK = {
    'DEFAULT_THROTTLE_CLASSES': [
        'rest_framework.throttling.AnonRateThrottle',
        'rest_framework.throttling.UserRateThrottle'
    ],
    'DEFAULT_THROTTLE_RATES': {
        'anon': '100/day',
        'user': '1000/day'
    }
}
 

Django Throttling

Setting up the throttle policy in APIVIEW

from rest_framework.response import Response
from rest_framework.throttling import UserRateThrottle
from rest_framework.views import APIView

class ExampleView(APIView):
    throttle_classes = [UserRateThrottle]

    def get(self, request, format=None):
        content = {
            'status': 'request was permitted'
        }
        return Response(content)
 

Django Throttling

Setting up the throttle policy using decorator

@api_view(['GET'])
@throttle_classes([UserRateThrottle])
def example_view(request, format=None):
    content = {
        'status': 'request was permitted'
    }
    return Response(content)
 

Django Throttling

Types

  • Annon Rate Throttle

  • User Rate Throttle

  • Scoped Throttle
  • Custom Throttle

 

 

Django Throttling

Lets dig down in implementation

Text

 

Django Throttling

Questions????

Text

 

Django Throttling

Django Throttling

By Muhammad AbdulMoiz

Django Throttling

Understanding and implementing Django Throttline

  • 444