I created my own view for login. However if a user goes directly to /admin it brings them to the admin login page and doesn\'t use my custom view. How can I make it redirect
I had the same issue, tried to use the accepted answer, but has the same issue as pointed in the comment above. Then I've did something bit different, pasting here if this would be helpful to someone.
def staff_or_404(u):
if u.is_active:
if u.is_staff:
return True
raise Http404()
return False
admin.site.login = user_passes_test(
staff_or_404,
)(admin.site.login)
The idea is that if the user is login, and tried to access the admin, then he gets 404. Otherwise, it will force you to the normal login page (unless you are already logged in)