我有一个使用 flask 和 flask-pymongo 的 api 我正在尝试处理登录功能并使用 passlib 尝试检查密码哈希是否匹配
调用端点时出现 500 服务器错误
我的代码如下:
def login():
email = request.form['email']
password = request.form['password']
# Find user record by email
user = db.user.find_one({'email': email})
# If user not found return message
if not user:
return jsonify(message='We cannot find you, please sign up')
# If user found check password and return token
hashed = user.password
test = pbkdf2_sha256.verify(password, hashed)
# Returns on success
if test:
access_token = create_access_token(identity=email)
return jsonify(message='Login Successful', access_token=access_token), 202
else:
return jsonify(message='Password incorrect'), 403
错误在这里
TypeError: The view function for 'login' did not return a valid response. The function either returned None or ended without a return statement.
127.0.0.1 - - [29/Aug/2021 20:24:37] "POST /login HTTP/1.1" 500 -
因为我是 Python 新手,所以我想知道我是否在这里正确使用了 return
hashed = user.password