1 2 3 4 5 6 7 8 9 10 | from django.contrib.auth.decorators import user_passes_test
def group_required(*group_names):
"""Requires user membership in at least one of the groups passed in."""
def in_groups(u):
if u.is_authenticated():
if bool(u.groups.filter(name__in=group_names)) | u.is_superuser:
return True
return False
return user_passes_test(in_groups)
|
More like this
- is_staff decorator by munhitsu 3 years, 5 months ago
- HTTP basic auth decorator by bthomas 3 years ago
- Auth decorators with 403 by Magus 4 years, 8 months ago
- login_required decorator that doesn't redirect by brutasse 11 months, 4 weeks ago
- Trigger a user password change by jedie 4 years, 5 months ago
Comments
For using it in urls.py shoud write
#