In a Django project I want to limit viewing of some views
to admin (the user for which request.user.is_superuser
is True
)
I know that I must use @permission_required(...)
before that view, but what is the argument for this?
Asked
Active
Viewed 883 times
0
1 Answers
0
Superusers are not handled by permission, they're handled solely by the is_superuser
field. You can use the @user_passes_test
decorator:
from django.contrib.auth.decorators import user_passes_test
@user_passes_test(lambda u: u.is_active and u.is_superuser)
def my_view(request):
...

knbk
- 52,111
- 9
- 124
- 122