Django: urls.py giving No Reverse Match error

105 Views Asked by At

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.
1

There are 1 best solutions below

5
On BEST ANSWER

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'),