这里需要request.user.is_authenticated()吗?

时间:2013-12-24 08:42:43

标签: django authentication django-authentication

我只为员工用户撰写视图。

def my_view(request):
    if request.user.is_staff:
        # show something to staff
    else:
        return my_view_404(request)

这个权限检查够了吗?任何缺陷?或者我应该检查request.user.is_authenticated()?

2 个答案:

答案 0 :(得分:2)

您无需检查is_authenticated()。未经身份验证的用户将在AnonymousUser中拥有request.user个对象,并且该类型的对象应毫无例外地对所有False次检查作出is_staff

答案 1 :(得分:0)

不需要request.user.is_staff将检查身份验证和员工状态。