0

I installed django-axes which allows you to set a url to redirect to upon 5 login failures. I added this line to settings.py per the documentation:

AXES_LOCKOUT_URL = 'account-locked'

I then added this line to users/urls.py:

path('account/locked/?username=<str>', user_views.account_locked, name='account-locked'),

When i input 5 incorrect username/password combos in the login screen, it attempts to redirect me, but I get this error:

NoReverseMatch at /login/
Reverse for 'account-locked?username=user2' not found. 'account-locked?username=user2' is not a valid view function or pattern name.
Tom
  • 364
  • 2
  • 19

1 Answers1

0

django-axes setting AXES_LOCKOUT_URL probably expects the path URL (not the path name)

So can you try changing AXES_LOCKOUT_URL like below:

AXES_LOCKOUT_URL = 'login/account/locked/'

And your path should look like this

path('account/locked/', user_views.account_locked, name='account-locked'),
KutayAslan
  • 494
  • 6
  • 13
  • thanks for the suggestion, i tried that but I got a 404 error: `Request URL: http://localhost:8000/login/account/locked/?username=user2` – Tom Apr 23 '21 at 19:51
  • @Tom Ah i see then it expects with "login/" prefix for some reason. Can you try changing this setting to AXES_LOCKOUT_URL = 'login/account/locked/' – KutayAslan Apr 23 '21 at 19:57
  • I still get the same 404 error with `AXES_LOCKOUT_URL = 'login/account/locked/'`. Would it have something to do with the parameters? Eg) `Reverse for 'account-locked?username=user2' not found. 'account-locked?username=user2' is not a valid view function or pattern name.` – Tom Apr 23 '21 at 20:21
  • @Tom, yes I've edited the answer. The queryparams shouldn't be written to path URL, this syntax meant to work with URL parameters not the queryparams. – KutayAslan Apr 23 '21 at 20:27
  • The answer you posted is very close, but I had to set `AXES_LOCKOUT_URL = 'account/locked/'` in settings.py, and `path('login/account/locked/', user_views.account_locked, name='account-locked'),` in urls.py. I'll mark your answer as correct – Tom Apr 23 '21 at 20:30