-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
A edited this page Aug 19, 2026
·
2 revisions
pip install nai-securityWith optional integrations:
pip install "nai-security[all]"Individual extras:
pip install "nai-security[axes]"
pip install "nai-security[ratelimit]"
pip install "nai-security[import-export]"
pip install "nai-security[unfold]"INSTALLED_APPS = [
# if using Unfold theme:
# "unfold",
# "import_export",
# "axes",
"nai_security",
]SecurityMiddleware must come after AuthenticationMiddleware. The package raises ImproperlyConfigured at startup if order is wrong.
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"nai_security.middleware.SecurityMiddleware",
"nai_security.middleware.RateLimitLoggingMiddleware", # optional
]GEOIP_PATH = "/var/lib/geoip/GeoLite2-Country.mmdb"
# or a directory containing GeoLite2-Country.mmdbGEOIP_PATH may be the .mmdb file or a directory; a directory is resolved to GeoLite2-Country.mmdb inside it.
Download DB:
python manage.py download_geoippython manage.py migrate nai_security
# or
python manage.py migrateThe package uses Django’s cache framework (django.core.cache). For production, configure Redis (or another shared cache), for example:
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
}
}redis is a declared dependency of nai-security because production deployments typically use it as the cache backend.
- Start your project
- Open admin → Security models appear
- Hit a blocked IP/country and confirm a
SecurityLogrow is created
Next: Configuration · Admin-Guide