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
76
votes
5 answers

flask-login: can't understand how it works

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 users list. However, I don't understand some things in this Flask-Login…
Sorin Vladu
  • 1,649
  • 3
  • 19
  • 35
62
votes
3 answers

How to use g.user global in flask

As I understand the g variable in Flask, it should provide me with a global place to stash data like holding the current user after login. Is this correct? I would like my navigation to display my user's name, once logged in, across the site. My…
Mittenchops
  • 15,641
  • 28
  • 103
  • 200
44
votes
2 answers

Flask-Login check if user is authenticated without decorator

From the Flask-Login docs, it's described how a user of the system can require an authenticated User-model to access a method utilising the decorator syntax: from flask_login import login_required @app.route("/settings") @login_required def…
Ospho
  • 2,538
  • 5
  • 23
  • 38
34
votes
8 answers

ImportError: No module named flask.ext.login

I have a problem with flask_login module. i have installed flask_login module successfully. Also from the command prompt i can run this script easily with no error: Python 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on…
curiousguy
  • 2,694
  • 6
  • 31
  • 55
28
votes
3 answers

Flask permanent session: where to define them?

By default, Flask uses volatile sessions, which means the session cookie is set to expire when browser closes. In order to use permanent sessions, which will use a cookie with a defined expiration date, one should set session.permanent = True, as…
patb
  • 1,338
  • 1
  • 14
  • 19
27
votes
3 answers

Flask-Login Password Reset

I'm using the flask-login library, and I haven't been able to find any good tutorials or documentation on how to go about allowing a user to reset their password through an email. What direction/resources can I look at on how to do this? A thorough…
Jason Brooks
  • 5,632
  • 6
  • 33
  • 47
27
votes
4 answers

Testing Flask login and authentication?

I'm developing a Flask application and using Flask-security for user authentication (which in turn uses Flask-login underneath). I have a route which requires authentication, /user. I'm trying to write a unit test which tests that, for an…
frnsys
  • 2,014
  • 2
  • 19
  • 23
24
votes
4 answers

How do I pass through the "next" URL with Flask and Flask-login?

The documentation for Flask-login talks about handling a "next" URL. The idea seems to be: User goes to /secret User is redirect to a login page (e.g. /login) After a successful login, the user is redirected back to /secret The only semi-full…
David White
  • 1,403
  • 2
  • 11
  • 24
24
votes
1 answer

Python Flask: keeping track of user sessions? How to get Session Cookie ID?

I want to build a simple webapp as part of my learning activity. Webapp is supposed to ask for user to input their email_id if it encounters a first time visitor else it remembers the user through cookie and automatically logs him/her in to carry…
pg2455
  • 4,095
  • 10
  • 43
  • 68
24
votes
1 answer

Using flask_login session with jinja2 templates

I have simple jinja2 template with registration/login links, I should hide them when user logged in, I also use flask_login module for this stuff. Question is: How should I identify is user logged in in jinja2 templates?
Slow Harry
  • 1,777
  • 3
  • 21
  • 40
21
votes
4 answers

sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string

I'm learning flask web microframework and after initialization of my database I run flask db init I run flask db migrate, to migrate my models classes to the database and i got an error. I work on Windows 10, the database is MySQL, and extensions…
21
votes
2 answers

is_authenticated() raises TypeError TypeError: 'bool' object is not callable

I tried to use is_authenticated() in a view, but got the error `TypeError: 'bool' object is not callable. Why am I getting this error and how do I fix it? @auth.before_app_request def before_request(): if current_user.is_authenticated() \ …
Gaoyang
  • 221
  • 1
  • 2
  • 5
21
votes
4 answers

py.test to test flask register, AssertionError: Popped wrong request context

I'm using flask to do register and login: from flask.ext.security.views import register, login class Register(Resource): def post(self): return register() class Login(Resource): def post(self): return…
Spirit
  • 553
  • 1
  • 6
  • 16
21
votes
5 answers

Implementing Flask-Login with multiple User Classes

I am writing an app that has multiple classes that function as Users (for example, a School Account and a Staff account). I'm trying to use Flask-Login to make this easy but I'm not quite sure how to make it, so that when a user logs in I can have…
Ashu Goel
  • 263
  • 2
  • 3
  • 7
20
votes
3 answers

How to track the current user in flask-login?

I m trying to use the current user in my view from flask-login. So i tried to g object I m assigning flask.ext.login.current_user to g object @pot.before_request def load_users(): g.user = current_user.username It works if the user is correct.…
naga4ce
  • 1,327
  • 3
  • 14
  • 21
1
2 3
58 59