这是我的aap.py文件 如果我提供的电子邮件和密码未注册,那么他们也可以进入/ login页面。在此行中引发错误“如果user.check_password(form.password.data)并且用户不是None:” 任何帮助将不胜感激。
@app.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.check_password(form.password.data) and user is not None:
login_user(user)
flash('Logged in successfully.')
# If a user was trying to visit a page that requires a login
# flask saves that URL as 'next'.
next = request.args.get('next')
# Checking if that next exists, otherwise we'll go to
# the welcome page.
if next == None or not next[0] == '/':
next = url_for('welcome_user')
return redirect(next)
return render_template("login.html", form=form) enter code here
答案 0 :(得分:0)
Python编译器从左向右移动,这意味着在仅使用and
运算符检查多个条件时,Python编译器首先检查第一个条件,如果为true,则移至第二个条件,以此类推,以获取后续条件。
结果,如果将给定的行更改为如下所示,则代码将按预期开始工作:
if user is not None and user.check_password(form.password.data):