0
0
Djangoframework~10 mins

Throttling for rate limiting in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the throttle class for rate limiting in Django REST Framework.

Django
from rest_framework.throttling import [1]
Drag options to blanks, or click blank then click option'
AUserRateThrottle
BAPIView
CIsAuthenticated
DSessionAuthentication
Attempts:
3 left
💡 Hint
Common Mistakes
Importing authentication or permission classes instead of throttle classes.
Using classes unrelated to rate limiting.
2fill in blank
medium

Complete the code to set the throttle classes in a Django REST Framework view.

Django
class MyView(APIView):
    throttle_classes = [[1]]
Drag options to blanks, or click blank then click option'
ASessionAuthentication
BAllowAny
CIsAuthenticated
DUserRateThrottle
Attempts:
3 left
💡 Hint
Common Mistakes
Using permission classes instead of throttle classes.
Forgetting to put the class inside a list.
3fill in blank
hard

Fix the error in the throttle rate setting in Django REST Framework settings.

Django
"DEFAULT_THROTTLE_RATES": {
    "user": "[1]"
}
Drag options to blanks, or click blank then click option'
A1000/hour
B1000 per hour
C100/hour
D1000/hourly
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect time units like 'hourly'.
Adding extra words like 'per'.
4fill in blank
hard

Fill both blanks to create a custom throttle class that limits requests to 10 per minute.

Django
from rest_framework.throttling import [1]

class CustomThrottle([2]):
    rate = '10/minute'
Drag options to blanks, or click blank then click option'
AUserRateThrottle
BBaseThrottle
CSimpleRateThrottle
DAnonRateThrottle
Attempts:
3 left
💡 Hint
Common Mistakes
Inheriting from the wrong base class.
Importing a class but not using it correctly.
5fill in blank
hard

Fill all three blanks to apply throttling globally in Django REST Framework settings.

Django
REST_FRAMEWORK = {
    'DEFAULT_THROTTLE_CLASSES': [
        '[1]',
    ],
    'DEFAULT_THROTTLE_RATES': {
        '[2]': '[3]'
    }
}
Drag options to blanks, or click blank then click option'
Arest_framework.throttling.UserRateThrottle
Buser
C1000/day
Drest_framework.permissions.IsAuthenticated
Attempts:
3 left
💡 Hint
Common Mistakes
Using permission classes instead of throttle classes in settings.
Mismatching throttle rate keys and classes.