首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >login_user()非类型对象没有带有flask_login的is_active属性

login_user()非类型对象没有带有flask_login的is_active属性
EN

Stack Overflow用户
提问于 2021-06-24 07:24:37
回答 1查看 23关注 0票数 0

我正在关注this tutorial,当我试图记住注册后登录的用户时,它不工作并显示'NoneType' object has no attribute 'is_active'错误,尽管它确实注册了用户,所以我不知道发生了什么,它以前是工作的,所以我知道问题不是在函数本身。

代码如下:

代码语言:javascript
运行
复制
def signup():
    if request.method == "POST":
        # getting information into backend
        email = request.form.get('email')
        user_name = request.form.get('userName')
        password_first = request.form.get('passwordFirst')
        password_confirm = request.form.get('passwordConfirm')

        # Checking if everything's ok

        user = User.query.filter_by(email=email).first()

        if user:
            flash("This email is already linked to an account", category="error")
        elif len(email) < 3:
            flash("Email must be at least 3 characters", category="error")
        elif len(user_name) < 2:
            flash("Username must be at least 2 characters", category="error")
        elif password_first != password_confirm:
            flash("Passwords don't match", category="error")
        elif len(password_first) < 8:
            flash("Password must be at least 8 characters long", category="error")

        # adding user to database
        else:
            new_user = User(email=email, user_name=user_name, password=generate_password_hash(password_first, method="sha256"))
            db.session.add(new_user)
            db.session.commit()
            login_user(user, remember=True)
            flash("Account created successfully! :)", category="success")
            return redirect(url_for("views.home"))


    return render_template("signup.html")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-24 10:12:50

应该用login_user(new_user, remember=True)代替login_user(user, remember=True)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68107992

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档