Luffy--------------(四)
一.频率限制短信接口 settings/dev.py: # drf配置 REST_FRAMEWORK = { # Throttling 'DEFAULT_THROTTLE_RATES': { 'user': None, 'anon': None, 'sms': '1/min' }, } apps/user/throttles.py: from rest_framework.throttling import SimpleRateThrottle class SMSRateThrottle(SimpleRateThrottle): scope = 'sms' def get_cache_key(self, request, view): # 针对手机号进行限制 mobile = request.data.get('mobile') or request.query_params.get('mobile') if not mobile: return None return self.cache_format % { 'scope': self.scope, 'ident': mobile } user/views.py: from libs.txm import get_code, send_sms from django.core.cache import cache from