浅谈Django REST Framework限速
作者:shhnwangjian 时间:2022-04-09 20:54:46
官方文档
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)
来源:http://www.cnblogs.com/shhnwangjian/p/7691950.html
标签:django,framework
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
js实现的全国省市二级联动下拉选择菜单完整实例
2023-09-09 05:21:01
![](https://img.aspxhome.com/file/2023/4/56304_0s.jpg)
asp读取xml实例代码
2011-03-08 11:13:00
python安装本地whl的实例步骤
2023-05-09 05:25:33
![](https://img.aspxhome.com/file/2023/5/121075_0s.png)
Python实现点云投影到平面显示
2021-05-10 14:51:15
如何在Python对Excel进行读取
2022-02-25 15:51:59
![](https://img.aspxhome.com/file/2023/9/115679_0s.png)
Python3安装pip工具的详细步骤
2021-09-27 15:38:09
![](https://img.aspxhome.com/file/2023/3/72923_0s.png)
为python设置socket代理的方法
2021-09-23 16:25:34
关于SQL中CTE(公用表表达式)(Common Table Expression)的总结
2012-08-21 10:22:21
Python分析微信好友性别比例和省份城市分布比例的方法示例【基于itchat模块】
2022-01-04 08:14:09
![](https://img.aspxhome.com/file/2023/4/114674_0s.png)
2019 Python最新面试题及答案16道题
2022-07-01 03:04:49
Python中的map()函数和reduce()函数的用法
2021-10-19 01:04:34
![](https://img.aspxhome.com/file/2023/0/110360_0s.png)
Python sklearn分类决策树方法详解
2023-04-20 17:14:13
![](https://img.aspxhome.com/file/2023/3/118013_0s.png)
asp之自动闭合HTML/ubb标签函数+简单注释
2008-09-29 12:21:00
python之线程池map()方法传递多参数list
2022-06-13 09:00:55
![](https://img.aspxhome.com/file/2023/6/131226_0s.jpg)
Python反爬虫伪装浏览器进行爬虫
2023-07-05 22:33:38
![](https://img.aspxhome.com/file/2023/6/109536_0s.jpg)
python 用opencv实现图像修复和图像金字塔
2022-09-27 09:24:22
![](https://img.aspxhome.com/file/2023/9/83929_0s.png)
如何愉快地迁移到 Python 3
2021-06-25 19:44:17
Tornado 多进程实现分析详解
2022-06-13 20:51:56
用python登录带弱图片验证码的网站
2023-04-28 12:22:22
![](https://img.aspxhome.com/file/2023/2/79692_0s.png)
简述 Python 的类和对象
2023-05-17 12:44:23