我已將這行代碼添加到我的登錄路徑中: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了解背景信息
添加回答
舉報
0/150
提交
取消