When I try to use staff_view, I get redirected in the admin authentication interface.
from django.contrib.admin.views.decorators import staff_member_required
@staff_member_required
def staff_view(request..):
...
How can I make a custom login, and not getting redirected in the default admin login interface?
You can use Django's user_passes_test decorator:
from django.contrib.auth.decorators import user_passes_test
@user_passes_test(lambda u:u.is_staff, login_url=reverse_lazy('foo'))
def staff_view(request..):
...
It's worth pointing out that staff_member_required
is a wrapper around user_passes_test
(see source code) and it also accepts a login_url
parameter, so you could do:
@staff_member_required(login_url=example_url)
def staff_view(request..):
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With