博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Django REST Framework限速
阅读量:6956 次
发布时间:2019-06-27

本文共 755 字,大约阅读时间需要 2 分钟。

官方文档:

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 Responsefrom rest_framework.throttling import UserRateThrottlefrom rest_framework.views import APIViewclass ExampleView(APIView):    throttle_classes = (UserRateThrottle,)    def get(self, request, format=None):        content = {            'status': 'request was permitted'        }        return Response(content)

 

转载地址:http://ismil.baihongyu.com/

你可能感兴趣的文章
SElinux以及防火墙的关闭
查看>>
android中dip、dp、px、sp和屏幕密度
查看>>
MySQL 可以用localhost 连接,但不能用IP连接的问题
查看>>
linux学习(之二)-初识linux的一些常用命令
查看>>
linux基础系统管理---系统管理
查看>>
重启网络出现RTNETLINK answers: File exists问题解决
查看>>
清空微信浏览器缓存debug页面清除法
查看>>
组策略 之 正确理解STARTER GPO
查看>>
分布式搜索elasticsearch的5种分片查询优先级
查看>>
python + selenium 弹出Alert提示窗, 自动确认。python语法注意
查看>>
PHP htmlspecialchars和htmlspecialchars_decode(函数)
查看>>
adt-bundle-windows-x86 出现的问题
查看>>
VHD and BitLocker
查看>>
我的友情链接
查看>>
菊花新
查看>>
OpenCASCADE Conic to BSpline Curves-Circle
查看>>
cacti监控
查看>>
ocp 052最新题库分享 20180530 又一次变题
查看>>
数据结构之二叉树(前序 中序 后续线索话非递归方式)
查看>>
CSS选择器
查看>>