28👍
✅
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..):
...
24👍
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..):
...
- [Django]-Serving large files ( with high loads ) in Django
- [Django]-Django: accessing session variables from within a template?
- [Django]-Manage.py : Unknown command: 'migrate'
Source:stackexchange.com