Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
If I understand the question correctly, this can be done through groups. You can write like this:
from django.contrib.auth.decorators import user_passes_test
# декоратор для проверки вхождения пользователя request.user в определенную группу
def group_required(*group_names):
def in_groups(user):
if user.is_authenticated():
if user.is_superuser or bool(user.groups.filter(name__in=group_names)):
return True
return False
return user_passes_test(in_groups)
# оборачиваем нужную функцию из views.py в декоратор. Проверяем входит ли пользователь request.user в группу name_of_group
@group_required('name_of_group')
def home(request):
pass
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question