Bird
0
0

You want to apply different rate limits for logged-in users and guests using Flask-Limiter. Which approach correctly achieves this?

hard📝 Conceptual Q8 of 15
Flask - Middleware and Extensions
You want to apply different rate limits for logged-in users and guests using Flask-Limiter. Which approach correctly achieves this?
ADisable Flask-Limiter for logged-in users
BUse a custom key_func that returns user ID if logged in, else IP address
CUse @limiter.limit decorators with fixed limits ignoring user info
DApply the same limit to all users regardless of login status
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to differentiate users

    To apply different limits, the key_func must distinguish logged-in users from guests.
  2. Step 2: Use a custom key_func

    Return user ID for logged-in users and IP for guests to apply separate limits.
  3. Final Answer:

    Use a custom key_func that returns user ID if logged in, else IP address -> Option B
  4. Quick Check:

    Custom key_func enables user-specific rate limits [OK]
Quick Trick: Custom key_func can differentiate user types for limits [OK]
Common Mistakes:
MISTAKES
  • Using same limit for all users
  • Ignoring user identity in key_func

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes