属性错误: 'Flask'对象没有属性'login_manager'



我正在做一个烧瓶项目,我通过填写登录表单来登录页面。但是,当我尝试从页面注销时,我得到 属性错误:"烧瓶"对象没有属性"login_manager"。搜索烧瓶文档后,我看到了如何使用login_manager模块,但烧瓶文档中的登录表单端点与我创建的端点不同,因此修改我的代码似乎是最好的解决方案。我在下面有我的登录端点代码:

@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')) 

感谢您的指导,帮助我正确退出页面。提前谢谢你

似乎通过删除login_required问题立即得到解决

相关内容

最新更新