django-axes is a Django plugin that actively monitors and tracks suspicious login attempts, helping to protect Django-powered sites from brute-force attacks. It can lock out users or IP addresses after a configurable number of failed attempts, supporting various tracking methods like IP, username, and user agent combinations. The library is currently at version 8.3.1 and is actively maintained by the Jazzband community, with a regular release cadence.
pip install django-axesVerified import paths — ran on the pinned version, not inferred.
To quickly set up django-axes, add 'axes' to `INSTALLED_APPS`, configure `AUTHENTICATION_BACKENDS` to include `AxesStandaloneBackend` at the top, and add `AxesMiddleware` to your `MIDDLEWARE` list, preferably at the end. Finally, run `migrate` to create necessary database tables and `check` to verify your configuration. You can then adjust settings like `AXES_FAILURE_LIMIT` and `AXES_COOLOFF_TIME`.
Review `axes.handlers.database.AxesDatabaseHandler` for new API calls and refactor any custom logic. Refer to the upgrade notes for specific changes.
Consult the version 7 upgrade notes in the official documentation. This will likely involve changes if you customized lockout responses or relied on the deprecated `AxesHttpRequest` object.
Explicitly define `AXES_USERNAME_FORM_FIELD = 'your_username_field_name'` in `settings.py` to match your user model's `USERNAME_FIELD` or your login form's username field.
Ensure `AUTHENTICATION_BACKENDS = ['axes.backends.AxesStandaloneBackend', 'django.contrib.auth.backends.ModelBackend', ...]`.
Configure a persistent and shared cache backend like Memcached or Redis (`django.core.cache.backends.memcached.MemcachedCache`, `django.core.cache.backends.redis.RedisCache`) for accurate tracking across multiple processes.
Upgrade to `django-axes` 5.32 or newer and set `AXES_RESET_COOL_OFF_ON_FAILURE_DURING_LOCKOUT = False` in your `settings.py` to prevent the cool-off period from resetting.