Python is#u authenticated()引发TypeError TypeError:';布尔';对象不可调用

Python is#u authenticated()引发TypeError TypeError:';布尔';对象不可调用,python,flask,flask-login,Python,Flask,Flask Login,我试图在视图中使用is\u authenticated(),但出现错误`TypeError:'bool'对象不可调用。为什么会出现此错误?如何修复 @auth.before_app_request def before_request(): if current_user.is_authenticated() \ and not current_user.confirmed \ and request.endpoint[:5] != 'au

我试图在视图中使用
is\u authenticated()
,但出现错误`TypeError:'bool'对象不可调用。为什么会出现此错误?如何修复

@auth.before_app_request
def before_request():
    if current_user.is_authenticated() \
            and not current_user.confirmed \
            and request.endpoint[:5] != 'auth.' \
            and request.endpoint != 'static':
        return redirect(url_for('auth.unconfirmed'))
自(2015年9月10日发布)起更改:

  • 中断:用户类的
    已通过身份验证
    处于活动状态
    匿名
    成员现在是属性,而不是方法。 应用程序应相应地更新其用户类
因此,您需要相应地更改
用户
类和代码。

当您试图将对象当作方法或函数来处理时,会出现“对象不可调用”错误

在这种情况下:

current_user.is_authenticated()
您的行为是当前用户。已作为方法进行身份验证,但它不是方法

您必须以这种方式使用它:

current_user.is_authenticated
在方法或函数之后使用“()”,而不是对象

在某些情况下,类可能实现
\uuuu call\uuu
函数,您也可以调用该函数的对象,然后它将是可调用的