Questions tagged [flask-login]

Flask-Login provides user session management for the python web framework Flask.

Flask-Login provides user session management for the web framework Flask. It handles the common tasks of logging in, logging out, and remembering your users' sessions over extended periods of time.

Flask-Login is not bound to any particular database system or permissions model. The only requirement is that your user objects implement a few methods, and that you provide a callback to the extension capable of loading users from their ID.

It will:

  • Store the active user’s ID in the session, and let you log them in and out easily.
  • Let you restrict views to logged-in (or logged-out) users.
  • Handle the normally-tricky “remember me” functionality.
  • Help protect your users’ sessions from being stolen by cookie thieves.
  • Possibly integrate with Flask-Principal or other authorization extensions later on.

However, it does not:

  • Impose a particular database or other storage method on you. You are entirely in charge of how the user is loaded.
  • Restrict you to using usernames and passwords, OpenIDs, or any other method of authenticating.
  • Handle permissions beyond “logged in or not.”
  • Handle user registration or account recovery.

For detailed information and examples, visit the flask-login documentation.

See also the official Github page.

879 questions
17
votes
2 answers

How to implement login required decorator in Flask

I have 2 Flask apps (different projects) that work together . One implements some API which uses tokens for auth. The second one consumes the API and makes a web interface for it. Now I have a login function that sends the username and password to…
utkbansal
  • 2,517
  • 2
  • 21
  • 42
17
votes
1 answer

Flask: Decorate every route at once?

I have @login_required decorator that decorates a controller action. However my app is very large and has tons of routes in many different controller files. Going one by one to decorate each route seems error prone (I could easily miss one) and time…
steve
  • 1,901
  • 3
  • 20
  • 34
17
votes
2 answers

TypeError: 'bool' object is not callable g.user.is_authenticated()

I am trying to do this in my Flask application. But I am getting an error like this TypeError: 'bool' object is not callable. Here is the corresponding code: @app.before_request def before_request(): g.user = current_user if…
Dopant Prashant
  • 183
  • 1
  • 1
  • 6
17
votes
3 answers

Flask-login AttributeError: 'User' object has no attribute 'is_active'

I have a problem with flask-login. After filling login form and clicking 'Submit' i'm get this error: Flask-login AttributeError: 'User' object has no attribute 'is_active' Some test users are created. And no problems with login template Traceback: …
bartezr
  • 843
  • 3
  • 9
  • 24
16
votes
2 answers

What does netloc mean?

I'm learning to make login function with Flask-login, and I'm facing with this code in my tutorial that I'm following: @app.route('/login', methods = ['GET', 'POST']) def login(): if current_user.is_authenticated: return…
Tri
  • 1,614
  • 2
  • 18
  • 44
16
votes
2 answers

What's the point of the "is_authenticated" method used in Flask-Login?

I'm working through the Flask Mega-Tutorial right now and I've come across this bit of code: class User(db.Model): id = db.Column(db.Integer, primary_key = True) nickname = db.Column(db.String(64), unique = True) email =…
user1787531
  • 609
  • 2
  • 9
  • 21
16
votes
2 answers

Flask-Login - How to get Session ID

Am doing a project with Flask, Gevent and web socket using flask development server environment. I used flask_login. Here how can get i get the Unique Session ID for each connection? I want to store the SessionID in the Database and delete it once…
14
votes
1 answer

Check if user is logged in with Flask-Login in template

When I log a user in, I set logged_in in the session, then check this value in the template. Is there a better way to check if the user is logged in with Flask-Login? session['logged_in'] = True login_user(user) {% if session['logged_in'] %} …
Maxtechwell
  • 173
  • 1
  • 1
  • 10
13
votes
2 answers

Flask-Login raises TypeError: 'bool' object is not callable when trying to override is_active property

I want to modify is_active in Flask-Login so that users are not always active. The default always returns True, but I changed it to return the value of the banned column. Based on the docs, is_active should be a property. However, the internal…
anvd
  • 3,848
  • 14
  • 58
  • 114
13
votes
2 answers

Flask-Login: Does not work on local machine but fine on hosting

I have a flask app, and I use flask-login, following tutorials (nothing fancy here) works fine on hosting works fine on my local MAC computer (at home) does not work on my local Linux computer (at office, which may be behind a firewall, but I am…
Emmet B
  • 4,321
  • 5
  • 30
  • 44
13
votes
3 answers

Flask-HttpAuth and Flask-Login

I am creating a small REST service. I am looking for different authentication methods. For sites I used the module Flask-Login. It seems the session authentication. The module Flask-HttpAuth provides the http and digest authentication methods. I am…
Victor Shelepen
  • 1,260
  • 10
  • 30
13
votes
1 answer

flask unit test: how to test request from logged in user

I'm writing some unit tests for my Flask web application and I'm trying to test the differences in the response between a request made by an anonymous user and a logged in user. I'm using the Flask-Login extension to implement the user…
Giovanni Di Milia
  • 11,340
  • 11
  • 48
  • 66
12
votes
4 answers

Does the order of decorators matter on a Flask view?

I'm using the login_required decorator and another decorator which paginates output data. Is it important which one comes first?
shalbafzadeh
  • 703
  • 7
  • 20
12
votes
1 answer

How do I call one Flask view from another one?

I have a JSON API in one blueprint module, and a web frontend in another one. I would like to shave off a few AJAX requests the client JS code would have to make by embedding some of the JSON it'll need in the frontend view template, before sending…
Dan Abramov
  • 241,321
  • 75
  • 389
  • 492
11
votes
2 answers

How to set current_user for pytest?

I'm writing a unit test for a view that uses the current logged in user in a query: @app.route('/vendors/create', methods=['GET', 'POST']) @login_required def create_vendors(): vendor_form = VendorForm(request.form) if…
ruipacheco
  • 11,526
  • 14
  • 63
  • 116
1
2
3
58 59