views:

133

answers:

1

Hello, I have written a django page that requires only super users to login. So I have added

foo_view = staff_member_required(foo_view)

but it doesn't cut, now I can control only allowing staff marked users to login but this doesn't cut. I have tried something like

def foo_view(request):
       if not request.user.is_superuser:
           #render some "not allowed page"
       #else render the page

but it doesn't seem to help as giving me errors.

+6  A: 

Try:

from django.contrib.auth.decorators import user_passes_test

def foo_view(request):
    # ...
foo_view = user_passes_test(lambda u: u.is_superuser)(foo_view)

Or (with Python >= 2.4):

from django.contrib.auth.decorators import user_passes_test

@user_passes_test(lambda u: u.is_superuser)
def foo_view(request):
    # ...
Dominic Rodger
+1 for reading my mind :]
kripto_ash
thanks alot Dominic!
Hellnar