我在 heroku 上使用 Django-ratelimit 时遇到限制器不起作用的问题。我没有收到任何错误。有什么建议我做错了吗?
视图.py
from django.core.cache import cache
from ratelimit.mixins import RatelimitMixin
[...]
class LoginView(RatelimitMixin, FormView):
ratelimit_key = 'user'
ratelimit_rate = '1/5m'
ratelimit_method = 'GET'
ratelimit_block = True
template_name = "account/login.html"
template_name_ajax = "account/ajax/login.html"
form_class = LoginUsernameForm
form_kwargs = {}
redirect_field_name = "next"
@method_decorator(sensitive_post_parameters())
@method_decorator(csrf_protect)
@method_decorator(never_cache)
def dispatch(self, *args, **kwargs):
return super(LoginView, self).dispatch(*args, **kwargs)
def get(self, *args, **kwargs):
if is_authenticated(self.request.user):
return redirect(self.get_success_url())
return super(LoginView, self).get(*args, **kwargs)
设置.py
# RATELIMIT SETTINGS
#RATELIMIT_CACHE_PREFIX = 'rl:'
RATELIMIT_ENABLE = True
RATELIMIT_USE_CACHE = 'default'
#RATELIMIT_VIEW = None