pyt*_*had 5 python django throttling django-rest-framework
文档说该期间应该是以下之一:('s', 'sec', 'm', 'min', 'h', 'hour', 'd', 'day')。我很好奇我是否可以将期间设置为类似的1/10min?
查看代码和文档,您不能“开箱即用”。但是我确实看到了根据现有油门之一制作自己的自定义油门的可能性:
from rest_framework.throttling import AnonRateThrottle
class AnonTenPerTenMinutesThrottle(AnonRateThrottle):
def parse_rate(self, rate):
"""
Given the request rate string, return a two tuple of:
<allowed number of requests>, <period of time in seconds>
So we always return a rate for 10 request per 10 minutes.
Args:
string: rate to be parsed, which we ignore.
Returns:
tuple: <allowed number of requests>, <period of time in seconds>
"""
return (10, 600)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1105 次 |
| 最近记录: |