Add example on custom lockout responses

Fixes #715
This commit is contained in:
Aleksi Häkli 2021-03-02 18:52:56 +02:00 committed by GitHub
parent 491b7f2381
commit 50a6baae2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -154,3 +154,22 @@ into ``my_namespace-username``:
authenticate. If you want to re-use the same function for consistency, that's
fine, but Axes does not inject these changes into the authentication flow
for you.
Customizing lockout responses
-----------------------------
Axes can be configured with ``AXES_LOCKOUT_CALLABLE`` to return a custom lockout response when using the plugin with e.g. DRF (Django REST Framework) or other third party libraries which require specialized formats such as JSON or XML response formats or customized response status codes.
An example of usage could be e.g. a custom view for processing lockouts.
``example/views.py``::
from django.http import JsonResponse
def lockout(request, credentials, *args, **kwargs):
return JsonResponse({"status": "Locked out due to too many login failures"}, status=403)
``settings.py``::
AXES_LOCKOUT_CALLABLE = "example.views.lockout"