question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception: No user_loader has been installed for this LoginManager

See original GitHub issue

For apps with multiple User models, is there any way to alter the user_loader / load_user() to be able to distinguish between the models? The standard is

@login_manager.user_loader
def load_user(user_id):
    return User.get(user_id)

I need to somehow discern which model the user_id passed belongs to and insert a condition to replace User.get() with the appropriate model.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13

github_iconTop GitHub Comments

10reactions
alanhamlettcommented, Apr 2, 2018

@davidism could you help release v0.4.2? Would you like me to submit a PR to update the changelog?

0reactions
BZ3R0commented, Sep 17, 2019

You must define the decorator at the same file you instantiated the login_manager. Assuming it’s on yourapp.py you shoud do like below:

login_manager = LoginManager(app)

@login_manager.user_loader
def load_user(id):
    return User.query.filter_by(user_id=id).first()

After that you can delete the @login_manager decorator and its respect function from your models.

Obs. This works on version 0.4.1 of Flask-Login

Read more comments on GitHub >

github_iconTop Results From Across the Web

flask-login:Exception: No user_loader has been installed for ...
I want to use flask_login to manager user login but some error like this: Exception: No user_loader has been ...
Read more >
Flask: No user_loader has been installed for this LoginManager
Error: Exception: No user_loader has been installed for this LoginManager. Refer tohttps://flask-login.readthedocs.io/en/latest/#how-it ...
Read more >
Flask-Login:Exception: No User_Loader Has Been Installed ...
This article will cover how to add authentication to your Flask app with the A user loader tells FlaskLogin how to find a...
Read more >
Flask-Login — Flask-Login 0.7.0 documentation
Once the actual application object has been created, you can configure it for ... It should return None (not raise an exception) if...
Read more >
Missing user_loader or request_loader Flask
No user loader has been installed. Exception: No user_loader has been installed for this LoginManager. Add one with the 'LoginManager.user_loader' decorator ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found