Sign in
There are a total of 2 posts.
2026-01-26
在 DRF 中實作範圍限制時,本文比較了兩種主流模式:ScopedRateThrottle 與 UserRateThrottle(或 SimpleRateThrottle)繼承。從實作位置、程式碼結構、擴充性與避免錯誤的角度,詳細說明何時選擇哪種寫法,並提供實際範例。
本指南深入說明 DRF 的請求限制(Throttling)功能,從全域設定、視圖/動作級別、ScopedRateThrottle 以及自訂 Throttle 的實作,並提供 Redis Cache、代理環境 IP 取得、競爭條件與 429/Retry-After 的實務建議,協助你同時提升 API 性能與安全性。