我已將這行代碼添加到我的登錄路徑中:profile_picture = url_for('static', filename='profile_pics/' + current_user.profile_picture)現(xiàn)在我的程序返回此錯(cuò)誤: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)我還導(dǎo)入了 LoginManager 包:from flask_login import LoginManager, login_required, login_user, current_user我無法注意到為什么我會(huì)收到此錯(cuò)誤。提前致謝。
1 回答

倚天杖
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊
您需要添加:
login = LoginManager(app)
在你之后app = Flask(__name__)
,我將繼續(xù):
login.login_view = 'login'
請(qǐng)參閱https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-v-user-logins了解背景信息
添加回答
舉報(bào)
0/150
提交
取消