flask-login: can't understand how it works

后端 未结 5 1701
离开以前
离开以前 2020-12-02 05:01

I\'m trying to understand how Flask-Login works.

I see in their documentation that they use a pre-populated list of users. I want to play with a database-stored user

5条回答
  •  执笔经年
    2020-12-02 05:32

    As per from the Flask-Login's document a user object must be returned and if the user id is not found it should return None instead of Exception.

    @login_manager.user_loader
    def load_user(userid):
        try:
            #: Flask Peewee used here to return the user object
            return User.get(User.id==userid)
        except User.DoesNotExist:
            return None
    

提交回复
热议问题