Flasklogin显示unicode类型而不是callab

2024-05-08 17:53:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用Flask Login来处理我的登录和会话。在

在注册过程中,一旦所有的细节验证,我可以使用登录用户(用户)并重定向到主页。在

我在登录过程中遇到问题。 尝试登录时,登录用户(user)中出现错误

'unicode' object is not callable'

在flask登录文档中,get_id()必须返回unicode,我已经这样做了。例如:

^{pr2}$

我已经导入了文本类型(从六个导入文本类型)。以前我只写了回信自身id。上面写着:

long object not callable

如何解决这个问题?在

以下是我的登录方法:

@app.route('/login', methods=['GET','POST'])
def login():
if request.method == 'POST':
    email = request.form['email']
    password = request.form['password']
    if email and password:
        error = "Invalid email/password!"
        user = session.query(User).filter_by(email=email).first()
        if user:
            hPass = hash_str(password)
            if user.password == hPass:
                login_user(user, remember=True)
                return redirect('/')
            else:
                return render_template('login.html', alert=render_template('alert.html', errormsg=error))
        else:
            return render_template('login.html', alert=render_template('alert.html', errormsg=error))

else:
    return render_template('login.html')

它在登录用户(user) 谢谢。在


Tags: 用户returnif过程emailrequesthtmllogin
1条回答
网友
1楼 · 发布于 2024-05-08 17:53:34

解决了!在

所以基本上,这个错误是由于在我的加载用户中使用了关键字'id'

改为:

def load_user(userid):
    user_id = int(userid)
    return User.query.get(user_id)

在我的用户类上:

^{pr2}$

相关问题 更多 >