我使用 Django ratelimiting http://django-ratelimit.readthedocs.org/en/v0.3.0/index.html 在开发中一切正常。
然而,在使用虚拟环境时它只是不起作用。速率限制(即视图)在它应该启动的时候没有启动,或者它根本没有启动。这两个环境之间的主要区别是我的设置文件被拆分了。IE
webtools_django15/
|-- __init__.py
|-- myapp
| |-- __init__.py
| |-- __init__.pyc
| |-- myapp.wsgi
| |-- myapp_settings.py
| |-- myapp_settings.pyc
| |-- myapp_urls.py
| |-- forms.py
| |-- forms.pyc
| |-- models.py
| |-- tests.py
| |-- views.py
| |-- views.py-bak
| `-- views.pyc
|-- manage.py
|-- modules
| |-- __init__.py
| `-- dnslookup.py
|-- static
| ! omitted !
|-- templates
| ! omitted !
`-- webtools_django15
|-- __init__.py
|-- __init__.pyc
|-- settings.py
|-- settings.py-bak
|-- settings.pyc
`-- urls.py
看法
@ratelimit(rate="5/s", method="POST", block=True)
@ratelimit(ip=True, rate="3/s", method="POST", block=True)
def report_ajax(request):
....
MYAPP.SETTINGS.PY
from settings import *
DEBUG = True
TEMPLATE_DEBUG = DEBUG
SITE_ID = 1
ROOT_URLCONF = 'myapp.myapp_urls'
TEMPLATE_DIRS = (
"/opt/django/webtools_django15/templates"
)
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',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'widget_tweaks',
'bootstrapform',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
设置.py
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
)
MANAGERS = ADMINS
DATABASES = {
'default': {
}
}
LOGIN_URL = '/login/'
TIME_ZONE = 'Europe/London'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
STATICFILES_DIRS = (
'/opt/django/webtools_django15/static/',
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
RATELIMIT_ENABLE = True
RATELIMIT_VIEW = "myapp.views.ratelimited"
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
MIDDLEWARE_CLASSES = (
'ratelimit.middleware.RatelimitMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
有任何想法吗 ??