Bird
0
0

You want to apply different throttle rates for authenticated and anonymous users in Django REST Framework. Which approach correctly implements this?

hard📝 Application Q15 of 15
Django - DRF Advanced Features
You want to apply different throttle rates for authenticated and anonymous users in Django REST Framework. Which approach correctly implements this?
ASet a single throttle class with rate '10/minute' and check user status inside get_cache_key
BUse middleware to block anonymous users after 5 requests per minute instead of throttling classes
CApply throttling only to authenticated users by setting throttle_classes conditionally in the view
DUse two throttle classes: one with 'user' scope for authenticated, one with 'anon' scope for anonymous, and add both to the view's throttle_classes
Step-by-Step Solution
Solution:
  1. Step 1: Understand throttling for different user types

    Django REST Framework supports multiple throttle classes to handle different user types separately.
  2. Step 2: Apply correct method

    Using two throttle classes with 'user' and 'anon' scopes and adding both to throttle_classes is the standard way.
  3. Final Answer:

    Use two throttle classes: one with 'user' scope for authenticated, one with 'anon' scope for anonymous, and add both to the view's throttle_classes -> Option D
  4. Quick Check:

    Multiple throttle classes handle user types separately [OK]
Quick Trick: Use separate throttle classes for user and anon [OK]
Common Mistakes:
MISTAKES
  • Trying to handle both user types in one throttle class
  • Using middleware instead of throttle classes
  • Conditionally setting throttle_classes in the view

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes