0

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?

M.javid
  • 6,387
  • 3
  • 41
  • 56
Branky
  • 373
  • 8
  • 23

1 Answers1

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