flask-login

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

邮差的信 提交于 2019-12-02 23:49:23
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: Traceback (most recent call last): File "C:\flask_prj\project\venv\lib\site-packages\flask\app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response) File "C:\flask_prj\project\venv\lib\site-packages\flask\app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) File "C:\flask_prj\project\venv\lib

TypeError: __init__() got an unexpected keyword argument 'password'

安稳与你 提交于 2019-12-02 08:46:27
问题 I can't find out what's the cause of this error TypeError: __init__() takes at most 2 arguments (3 given) which is pointing to @user_blueprint.route('/login', methods=['GET', 'POST']) def login(): if g.user.is_authenticated: flash("You are already Logged in", 'warning') return redirect(url_for('members')) error = "" form = LoginForm() if request.method == 'POST': if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is not None and bcrypt.check

Flask-Login not working with two applications on same domain

故事扮演 提交于 2019-12-02 05:43:47
问题 I have been using Flask-Login on <domain>/<app_1> for almost a year without issue. Recently, I built a second application with the same stack and deployed it to <domain>/<app_2> . Now, whenever I log into either app, it kicks me out of the other. Is there a reason for this? The apps have different databases and secret keys, and I would have assumed I could have two cookies for the same domain. I'm not too familiar with cookies and am not sure how to debug this. I'm happy to provide headers or

Flask-Login not working with two applications on same domain

妖精的绣舞 提交于 2019-12-02 00:10:16
I have been using Flask-Login on <domain>/<app_1> for almost a year without issue. Recently, I built a second application with the same stack and deployed it to <domain>/<app_2> . Now, whenever I log into either app, it kicks me out of the other. Is there a reason for this? The apps have different databases and secret keys, and I would have assumed I could have two cookies for the same domain. I'm not too familiar with cookies and am not sure how to debug this. I'm happy to provide headers or other information if people can tell me what is relevant. You need to configure the cookies to use

@login_required trouble in flask app

感情迁移 提交于 2019-12-01 16:08:46
I have created a blueprint that handles authenticating. This blue print uses Flask-Login. And has the following, as well as more code not shown. In the blueprint I have the following: from flask.ext.login import LoginManager from flask.ext.login import UserMixin from flask.ext.login import current_user from flask.ext.login import login_required from flask.ext.login import login_user from flask.ext.login import logout_user auth_print = Blueprint('auth_print', __name__) login_manager = LoginManager() login_manager.login_view = '/login' class User(UserMixin): user_store = {} # Stores the users

Store post data for use after authenticating with Flask-Login

倾然丶 夕夏残阳落幕 提交于 2019-12-01 11:04:49
Each article page has a form for logged in users to add a comment. I want users to be able to comment even if they haven't logged in yet. They should be redirected to the login page, and then the comment should be added. However, when Flask-Login's login_required redirects back to the page, it is not a POST request, and the form data is not preserved. Is there a way to preserve the POST data after logging in and redirecting? @articles.route('/articles/<article_id>/', methods=['GET', 'POST']) def article_get(article_id): form = CommentForm(article_id=article_id) if request.method == 'POST': if

Flask-Login shows 401 instead of redirecting to login view

孤街醉人 提交于 2019-12-01 08:58:10
Using Flask-Login, I want to require login for some views. When I try to access a view that is decorated with @login_required , I get a 401 message instead of the login page. How do I set this up correctly? from flask_login import LoginManager, login_required, login_user login_manager = LoginManager() login_manager.init_app(app) @login_manager.user_loader def load_user(user_id): return User.get(user_id) @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': # authenticate user from form login_user(user) return redirect(url_for('index')) return render_template(

Accessing Flask Session variables from Flask Navigation for dynamic navigation menu

回眸只為那壹抹淺笑 提交于 2019-12-01 08:58:04
I want to have a dynamic navigation menu that shows "Login" if the user is not currently logged on, and "Logout" if the user is logged in. I'm using code similar to the following: import flask import flask_nav import flask_nav.elements as fne frontend = flask.Blueprint('frontend', __name__) application = flask.Flask(__name__) mySess = flask_session.Session() flask_appconfig.AppConfig(application) flask_bootstrap.Bootstrap(application) application.register_blueprint(frontend) application.config['BOOTSTRAP_SERVE_LOCAL'] = True application.config['SSL'] = True application.secret_key = SECRET_KEY

Store post data for use after authenticating with Flask-Login

北城以北 提交于 2019-12-01 08:00:32
问题 Each article page has a form for logged in users to add a comment. I want users to be able to comment even if they haven't logged in yet. They should be redirected to the login page, and then the comment should be added. However, when Flask-Login's login_required redirects back to the page, it is not a POST request, and the form data is not preserved. Is there a way to preserve the POST data after logging in and redirecting? @articles.route('/articles/<article_id>/', methods=['GET', 'POST'])

Flask-Login shows 401 instead of redirecting to login view

Deadly 提交于 2019-12-01 06:06:12
问题 Using Flask-Login, I want to require login for some views. When I try to access a view that is decorated with @login_required , I get a 401 message instead of the login page. How do I set this up correctly? from flask_login import LoginManager, login_required, login_user login_manager = LoginManager() login_manager.init_app(app) @login_manager.user_loader def load_user(user_id): return User.get(user_id) @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': #