Use the user_passes_test
decorator:
from django.contrib.auth.decorators import user_passes_test
@user_passes_test(lambda u: u.is_superuser)
def my_view(request):
...
More Related Contents:
- View doesn’t return HttpResponse
- Hi I am new to Django Framework.getting error :No Module Named
- Why does DEBUG=False setting make my django Static Files Access fail?
- How to use permission_required decorators on django class-based views
- Django – after login, redirect user to his custom page –> mysite.com/username
- Django : How can I see a list of urlpatterns?
- Django get the static files URL in view
- Execute code in Django after response has been sent to the client
- django – get() returned more than one topic
- How to handle request.GET with multiple variables for the same parameter in Django
- django: Purpose of django.utils.functional.SimpleLazyObject?
- Provide extra context to all views
- Can I call a view from within another view?
- Raw SQL queries in Django views
- How can I list urlpatterns (endpoints) on Django?
- Example of Django Class-Based DeleteView
- Redirect / return to same (previous) page in Django?
- Django – show loading message during long processing
- How to handle “matching query does not exist” when getting an object
- What is the right way to validate if an object exists in a django view without returning 404?
- Forbidden (403) CSRF verification failed. Request aborted
- CSRF verification failed. Request aborted. on django
- Multiple form classes in django generic (class) views
- Extending the User model with custom fields in Django
- log all sql queries
- How to define two fields “unique” as couple
- Creating a extended user profile
- multiple files upload using same input name in django
- Django REST Framework image upload
- Django: dynamic database file