淺談Django REST Framework限速
更新時間:2017年12月12日 11:12:23 作者:shhnwangjian
這篇文章主要介紹了淺談Django REST Framework限速,具有一定借鑒價值,需要的朋友可以參考下。
settings.py配置
REST_FRAMEWORK = { 'DEFAULT_THROTTLE_CLASSES': ( 'rest_framework.throttling.AnonRateThrottle', 'rest_framework.throttling.UserRateThrottle' ), 'DEFAULT_THROTTLE_RATES': { 'anon': '100/day', 'user': '1000/day' } }
AnonRateThrottle:用戶未登錄請求限速,通過IP地址判斷
UserRateThrottle:用戶登陸后請求限速,通過token判斷
DEFAULT_THROTTLE_RATES 包括 second, minute, hour, day
引用樣例:
from rest_framework.response import Response from rest_framework.throttling import UserRateThrottle from rest_framework.views import APIView class ExampleView(APIView): throttle_classes = (UserRateThrottle,) def get(self, request, format=None): content = { 'status': 'request was permitted' } return Response(content)
總結
以上就是本文關于淺談Django REST Framework限速的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
相關文章
pytorch 實現(xiàn)張量tensor,圖片,CPU,GPU,數(shù)組等的轉換
今天小編就為大家分享一篇pytorch 實現(xiàn)張量tensor,圖片,CPU,GPU,數(shù)組等的轉換,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-01-01