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

问题描述 投票:0回答:1

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

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

我将感谢您的指导,帮助我正确地从页面中注销。先谢谢你

python flask logout
1个回答
0
投票

似乎通过删除login_required这个问题就立即解决了。

© www.soinside.com 2019 - 2024. All rights reserved.