view.py
@login_required @permission_required('is_superuser') def score_reset(request): pass
url.py
url(r'^score-reset/$', score_reset, name='score-reset'),
I have the following code and to my surprise I still hit the function, despite being logged in with a non superuser. I was expecting to get a permission denied.
What am I missing?
Django admin allows access to users marked as is_staff=True . To disable a user from being able to access the admin, you should set is_staff=False . This holds true even if the user is a superuser. is_superuser=True .
A Django superuser, is its name implies, means it's a user with 'super' permissions. By extension, this means a superuser has access to any page in the Django admin, as well as permissions to Create, Read, Update and Delete any type of model record available in the Django admin.
is_superuser
isn't a permission, it's an attribute on the user model. Django already has another decorator you can make use of called user_passes_test
to perform this check:
from django.contrib.auth.decorators import user_passes_test @user_passes_test(lambda u: u.is_superuser) def score_reset(self,...): ...
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