![](/img/trans.png)
[英]'NoneType' object has no attribute 'check_password'
[英]builtins.AttributeError: 'NoneType' object has no attribute 'check_password'
這是我的aap.py文件。如果我提供未注冊的電子郵件和密碼,那么他們也可以進入/ login頁面。 此行引發錯誤“如果user.check_password(form.password.data)並且user不是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
Python編譯器從左向右移動,這意味着在僅使用and
運算符檢查多個條件時,Python編譯器首先檢查第一個條件,如果為true,則移至第二個條件,以此類推。條件。
結果,如果將給定的行更改為如下所示,則代碼將按預期開始工作:
if user is not None and user.check_password(form.password.data):
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.