亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

添加一行代碼時出現此錯誤.... AttributeError: 'Flask'

添加一行代碼時出現此錯誤.... AttributeError: 'Flask'

牧羊人nacy 2022-10-05 18:30:06
我已將這行代碼添加到我的登錄路徑中:profile_picture = url_for('static', filename='profile_pics/' + current_user.profile_picture)現在我的程序返回此錯誤:AttributeError: 'Flask' object has no attribute 'login_manager'這是我的登錄路線:@app.route("/login", methods=["GET", "POST"])def login():    session.clear()    if request.method == "GET":        return render_template("login.html")    if request.method == "POST":        rows = User.query.filter_by(username=request.form.get("username")).first()        if rows is None or not check_password_hash(rows.password, request.form.get("password")):            flash('Usuario o contrase?a incorrectos')            return render_template("login.html")        else:            profile_picture = url_for('static', filename='profile_pics/' + current_user.profile_picture)            session["user_id"] = rows.user_id            return render_template("profile.html", name=rows.name, genre=rows.genre, profile_picture=profile_picture)我還導入了 LoginManager 包:from flask_login import LoginManager, login_required, login_user, current_user我無法注意到為什么我會收到此錯誤。提前致謝。
查看完整描述

1 回答

?
倚天杖

TA貢獻1828條經驗 獲得超3個贊

您需要添加:

login = LoginManager(app)

在你之后app = Flask(__name__),我將繼續:

login.login_view = 'login'

請參閱https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-v-user-logins了解背景信息


查看完整回答
反對 回復 2022-10-05
  • 1 回答
  • 0 關注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號