首页 > Flask login 'function' object has no attribute 'is_active'

Flask login 'function' object has no attribute 'is_active'

我在用flask框架做login模块时, 遇到这个错误,
AttributeError: 'User' object has no attribute 'is_active'

相关代码段:

@auth.route('/login', methods=['GET', 'POST'])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user, form.remember_me.data)
            return redirect(request.args.get('next') or url_for('main.index'))
        flash('Invalid username or password.')
    return render_template('auth/login.html', form=form)

我不知道哪出了问题, 谁能帮我看看?


User这个数据库模型里面没有is_active,你的user,没有继承,UserMixin,
http://flask-login.readthedocs.org/en/latest/#flask.ext.login.UserMixin
http://docs.jinkan.org/docs/flask-login/
http://www.oschina.net/translate/the-flask-mega-tutorial-part-v-user-logins
2种方法,
一种你自己写,一种继承他

【热门文章】
【热门文章】