我已经在我的项目上设置了django ratelimit,它似乎运行得很好,只是当访问者达到其限制时,我无法删除难看的403错误页面。我正试图取代他们在文件中所说的:
There is optional middleware to use a custom view to handle Ratelimited exceptions. To use it, add ratelimit.middleware.RatelimitMiddleware to your MIDDLEWARE_CLASSES (toward the bottom of the list) and set RATELIMIT_VIEW to the full path of a view you want to use.
The view specified in RATELIMIT_VIEW will get two arguments, the request object (after ratelimit processing) and the exception.
我的代码如下:
设置:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'ratelimit.middleware.RatelimitMiddleware',
)
RATELIMIT_VIEW = 'myapp.views.beenLimited'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'myapp',
'ratelimit',
)
RATELIMIT_USE_CACHE = 'default'
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'ratelimit-tests',
},
}
观点:
^{pr2}$我做错什么了?在
我不确定此帮助是否正确,请尝试修复
beeLimited
视图以更正它另一种方法是在
pullFromDatabase
视图中检查request.limited
属性。它将需要设置block=True
。在相关问题 更多 >
编程相关推荐