1

Djangoレート制限を使用していますhttp://django-ratelimit.readthedocs.org/en/v0.3.0/index.html devではすべて正常に動作します。

ただし、仮想環境を使用する場合、本番環境では機能しません。レート制限 (つまり、ビュー) が必要なときに開始されないか、まったく開始されないかのいずれかです。2 つの環境の主な違いは、設定ファイルが分割されていることです。すなわち

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',
)

何か案は ??

4

1 に答える 1