[英]AttributeError: 'Flask' object has no attribute 'login_manager'
I'm working on a flask project where I log in a page by filling a login form.我正在处理 flask 项目,我通过填写登录表单登录页面。 However when I try to logout from the page I get AttributeError: 'Flask' object has no attribute 'login_manager' .但是,当我尝试从页面注销时,我得到AttributeError: 'Flask' object has no attribute 'login_manager' 。 After searching the flask documentation I saw how the login_manager module is used but the login form endpoint in the flask documentation was different from the one I created, so modifying my code seems the best solution.在搜索 flask 文档后,我看到了 login_manager 模块的使用方式,但 flask 文档中的登录表单端点与我创建的不同,因此修改我的代码似乎是最好的解决方案。 I have my login endpoint code down below:我在下面有我的登录端点代码:
@app.route('/simpleuser') //returns the user page where I have a logout button
def simpleuser():
return render_template('simple.html')
@app.route('/login' , methods = ['GET' , 'POST'])
def login():
if request.method == 'POST':
loginuser = users.find_one({"Email":request.form['Email']}) //if email exists
if loginuser: //if password matches a hashed password
if bcrypt.check_password_hash(loginuser['Password'],request.form['Password']):
session['Email'] = request.form['Email']
if loginuser["User"]=="Simple":
return redirect(url_for('simpleuser')) //my page where I can logout
return 'Invalid email/password combination'
return 'Invalid email'
return render_template('login.html')
@app.route('/logout')
@login_required
def logout():
# remove the email from the session if it's there
session.pop('Email', None)
return redirect(url_for('home'))
I would appreciate your guidance with helping me logout from the page correctly.感谢您的指导,帮助我正确地从页面注销。 Thank you in advance先感谢您
It seems that by removing login_required the problem is immediatelly solved似乎通过删除 login_required 问题立即得到解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.