Bird
0
0

You want to apply different throttle rates to different API endpoints using ScopedRateThrottle. What must you do to make it work?

medium📝 Debug Q7 of 15
Django - DRF Advanced Features
You want to apply different throttle rates to different API endpoints using ScopedRateThrottle. What must you do to make it work?
ASet throttle rates only in the view's get method
BDefine 'throttle_scope' attribute on views and set rates in settings
CUse UserRateThrottle instead of ScopedRateThrottle
DAdd throttle classes to middleware instead of views
Step-by-Step Solution
Solution:
  1. Step 1: Understand ScopedRateThrottle usage

    ScopedRateThrottle requires a 'throttle_scope' string on the view to identify the rate.
  2. Step 2: Configure settings

    Throttle rates for each scope must be defined in 'DEFAULT_THROTTLE_RATES' in settings.
  3. Final Answer:

    Define 'throttle_scope' attribute on views and set rates in settings -> Option B
  4. Quick Check:

    ScopedRateThrottle needs scope attribute and settings rates [OK]
Quick Trick: ScopedRateThrottle needs throttle_scope and matching settings [OK]
Common Mistakes:
MISTAKES
  • Trying to set rates inside view methods
  • Using UserRateThrottle when scoped limits are needed
  • Adding throttling to middleware instead of views

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes