zoukankan      html  css  js  c++  java
  • 频率组件

    -频率是什么?节流,访问控制
            
            -内置的访问频率控制类SimpleRateThrottle
            -写一个类,继承SimpleRateThrottle
            -class MyThrottle(SimpleRateThrottle):
                scope='aaa'
                def get_cache_key(self, request, view):
                    return self.get_ident(request)
            -在setting中:
                REST_FRAMEWORK = {
                    'DEFAULT_THROTTLE_RATES':{
                        'aaa':'10/m'
                    }
                }
            
            -使用
                局部使用:
                    -在视图类中写
                    throttle_classes = [MyThrottle,]
                全局使用:
                    -在setting中写
                     'DEFAULT_THROTTLE_CLASSES':['app01.MyAuth.MyThrottle',],
            
                    -局部禁用:
                        -在视图类中写
                        throttle_classes = []
                        
                        
        
            错误信息改成中文显示:
                def throttled(self, request, wait):
                    class MyThrottled(exceptions.Throttled):
                        default_detail = '傻逼'
                        extra_detail_singular = '还剩 {wait} 秒.'
                        extra_detail_plural = '还剩 {wait} 秒'
    
                    raise MyThrottled(wait)
  • 相关阅读:
    Markdown快捷笔记
    Linux常用命令
    Git使用
    HTML
    JavaScript-笔记2
    AngularJS-笔记2
    AngularJS-笔记1
    JQuery-笔记
    设置DataGridView的某个单元格为ComboBox
    记录文件浏览历史路径
  • 原文地址:https://www.cnblogs.com/xuqidong/p/13912351.html
Copyright © 2011-2022 走看看