官方文档:http://www.django-rest-framework.org/api-guide/throttling/#throttling

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)

最新文章

  1. PHP 文件包含总结 include require 命名空间 autoload spl_autoload_register 读取文件路径
  2. 【图像处理】【SEED-VPM】6.文件目录结构
  3. spring注解注入失败一个原因
  4. jQuery年月日(生日)选择器
  5. RHEL 5.4下部署LVS(DR)+keepalived实现高性能高可用负载均衡
  6. Part 1 What is AngularJS
  7. 完全卸载Oracle方法
  8. @Index用法——javax.persistence.Index
  9. 7.使用ProcessBuilder执行本地命令(转)
  10. codeforces 622C. Optimal Number Permutation 构造
  11. 处理程序“svc-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
  12. 六行python代码的爱心曲线
  13. CollapsingToolbarLayout使用
  14. STM32学习笔记(二):GPIO口工作原理
  15. 关于jeesite的陷阱需要注意
  16. Nestjs 缓存
  17. Android: android studio配置生成自定义apk名称
  18. WPF Combobox选中事件
  19. IQueryable与IEnumerable
  20. 计数排序/Counting Sort

热门文章

  1. iOS 通知推送APNS
  2. Nginx geoip模块
  3. 数据库中事务的四大特性(ACID)
  4. pycharm中查看源码的快捷键
  5. NoClassDefFoundError与ClassNotFoundException
  6. python3.7之12306抢票脚本实现
  7. HDU3480-Division-斜率dp
  8. Biorhythms POJ - 1006 中国剩余定理
  9. P2084 进制转换
  10. 「SCOI2014」方伯伯运椰子 解题报告