How is Flask-Login's request_loader related to user_loader?

后端 未结 3 1876
被撕碎了的回忆
被撕碎了的回忆 2021-02-08 11:07

I apologize in advance for asking a rather cryptic question. However, I did not understand it despite going through a lot of material. It would be great if you could shed some

3条回答
  •  独厮守ぢ
    2021-02-08 11:32

    From the Flask-Login documentation:

    Sometimes you want to login users without using cookies, such as using header values or an api key passed as a query argument. In these cases, you should use the request_loader callback. This callback should behave the same as your user_loader callback, except that it accepts the Flask request instead of a user_id.

    So, to answer your question, they both serve the same function for Flask-Login. They are both used to load the user. request_loader, however, is appropriate for custom logins.

    Here's a great tutorial I found that utilizes request_loader to take advantage of token based authentication (The post is not my own, I'm merely sharing the link): http://gouthamanbalaraman.com/blog/minimal-flask-login-example.html

提交回复
热议问题