相关疑难解决方法(0)

Flask-Login引发TypeError:尝试覆盖is_active属性时,'bool'对象不可调用

我想is_active在Flask-Login中进行修改,以便用户不会始终处于活动状态.

默认值始终返回True,但我更改了它以返回banned列的值.

根据文档,is_active应该是一个属性.但是,内部Flask-Login代码引发:

TypeError: 'bool' object is not callable 
Run Code Online (Sandbox Code Playgroud)

试图使用时is_active.

如何正确使用is_active停用某些用户?

class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    banned = db.Column(db.Boolean, default=False)

    @property
    def is_active(self):
        return self.banned
Run Code Online (Sandbox Code Playgroud)
login_user(user, form.remember_me.data)

if not force and not user.is_active():
TypeError: 'bool' object is not callable
Run Code Online (Sandbox Code Playgroud)

python flask flask-login

8
推荐指数
1
解决办法
5749
查看次数

标签 统计

flask ×1

flask-login ×1

python ×1