if request.user.is_authenticated(): TypeError: ‘bool‘ object is not callable

报错: if request.user.is_authenticated():
TypeError: ‘bool’ object is not callable
在用户校验的时候报的错。错误提示bool类型的不可以调用。
  这块是由于因为 is_authenticated是属性而不是方法。在django1.几的版本中is_authenticated是方法,因此可以如上调用,但是在3.1.1等版本中,is_authenticated是方法,因此上述判断需要改为

if request.user.is_authenticated:

即可使用该属性校验

猜你喜欢

转载自blog.csdn.net/qq_45701131/article/details/109146023