From 50a6baae2a351d07838d98de242eeea191ce4361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksi=20H=C3=A4kli?= Date: Tue, 2 Mar 2021 18:52:56 +0200 Subject: [PATCH] Add example on custom lockout responses Fixes #715 --- docs/5_customization.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/5_customization.rst b/docs/5_customization.rst index d047923..ae91cf6 100644 --- a/docs/5_customization.rst +++ b/docs/5_customization.rst @@ -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"