[英]user_passes_test decorator redirecting to login even when result is True
This is my decorator: 这是我的装饰器:
def is_clinic(user):
user.groups.filter(name='Klinik').exists()
And my view: 我的看法是:
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")
user is in group. 用户在组中。 I tested it with shell and decorator is returning True for sure.
我用shell测试了,装饰器肯定会返回True。
When i navigate to url, django is redirecting me to clinic_only.html
当我导航到url时,django将我重定向到
clinic_only.html
You have forgotten to return the result of your query. 您忘记了返回查询结果。 Therefore, your function implicitly returns
None
, and the decorator redirects to the login page. 因此,您的函数隐式返回
None
,并且装饰器重定向到登录页面。 You should have: 你应该有:
def is_clinic(user):
return user.groups.filter(name='Klinik').exists()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.