I am having issue with Login_manager in my application . The error is thrown here

我在我的应用程序中遇到Login_manager问题。这里抛出了错误

def authenticate(form):
    if form.validate_on_submit():
        try:
            user = session.query(User).filter(User.email == form.email.data).first()
        except :# models.DoesNotExist:
            flash("Your email or password does not match !", "error")
        else :
            if check_password_hash(user.password,form.password.data):
                login_user(user)
                flash("You've been logged in", "success")
                return redirect(url_for('index'))
            else :
                flash("Your email or password does not match !", "error")
    return render_template('login.html',form = form)  

The issue is raise at

问题是提出来的

login_user(user)

login_user(用户)

my login_manager is configured below the autheticate as follows.

我的login_manager配置在authenticicate下面,如下所示。

if __name__ == '__main__':

    app.secret_key = 'Innalhamdulillah.nahmaduhu.taalanastainubihi.wanastagfiruh!'
    app.run(debug = DEBUG, host=HOST, port= PORT)

    login_manager = LoginManager()
    login_manager.init_app(app)
    login_manager.login_view = 'login'

    @login_manager.user_loader
    def load_user(userid):
        try:
            return session.query(User).filter(User.id == userid).first()
        except models.DoesNotExist :
            return None

and in my declaration

并在我的声明中

from flask.ext.login import LoginManager,login_user

Please how do i addressed this issue and what is the cause ? How do i better understand it ? I was suspecting my def load_user(userid): bcos i am not very much clear and this my first. Any help would be appreciated.

请问我该如何解决这个问题,原因是什么?我怎样才能更好地理解它?我怀疑我的def load_user(userid):bcos我不是很清楚,这是我的第一次。任何帮助,将不胜感激。

1 个解决方案

#1


12

You run your app before initializing the LoginManager. So you should have:

在初始化LoginManager之前运行应用程序。所以你应该:

app.secret_key = 'xxxxyyyyyzzzzz'

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'

app.run(debug = DEBUG, host=HOST, port= PORT)

更多相关文章

  1. 轮询Web服务的最佳方式(例如,对于Twitter应用程序)
  2. 乘客的Django应用程序显示空主页
  3. 用于在Google App Engine上构建应用程序的最佳开源IDE?
  4. 获取Android应用程序的Linux UID
  5. 在Linux中的脚本中安装应用程序
  6. 如何发送一个字节(或字节)来测试在我的应用程序中监听的套接字?
  7. 〖Linux〗使用Qt5.2.0开发Android的NDK应用程序
  8. 如何测试已部署的Web应用程序
  9. window下使用vnc远程登录linux图形界面和运行应用程序 和odroid

随机推荐

  1. PHP下载远程文件到指定目录
  2. Centos下PHP5升级PHP7
  3. PHP发送邮件:如何自定义reply-to头部以及
  4. mac切换PHP版本并使当前PHP版本生效
  5. PHP_CodeSniffer安装和使用教程(自动代码
  6. php程序员经常忽略的冷门知识点
  7. Laravel 批量插入(insert)数据
  8. php中SSL certificate https问题解决方案
  9. php设置随机ip访问
  10. Laravel数据库获取值的常用方法