这是我的装饰器:
def is_clinic(user):
user.groups.filter(name='Klinik').exists()
和我的观点:
class Index(View):
@method_decorator(login_required)
@method_decorator(user_passes_test(is_clinic, login_url='/clinic_only.html'))
def get(self, request):
return render(request,"index.html")
用户在组中。我用外壳进行了测试,装饰师肯定会返回。
当我导航到URL时,Django将我重定向到clinic_only.html
您忘记了返回查询结果。因此,您的功能隐式返回None
,并且装饰器将重定向到登录页面。您应该有:
def is_clinic(user):
return user.groups.filter(name='Klinik').exists()