Throttle API Requests
A snippet showing how to enable API throttling in DRF.
# settings.py
REST_FRAMEWORK = {
"DEFAULT_THROTTLE_CLASSES": [
"rest_framework.throttling.AnonRateThrottle",
"rest_framework.throttling.UserRateThrottle",
],
"DEFAULT_THROTTLE_RATES": {
"anon": "100/hour",
"user": "1000/hour",
},
}
Explanation:
- DRF automatically enforces rate limits per IP/user; 429 is returned when exceeded.
- Category Django REST Framework (DRF)
- Total Views 727
- Last Modified 07 July, 2026
- Tags #drf #throttling #api #security
Previous snippet
Versioning APIs
Next snippet