Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

python 3.x - upgrade to flask-login-0.5.0 from Flask-Login-0.4.1 redirected you too many times error

after upgrade from Flask-Login-0.4.1 to flask-login-0.5.0 my old code can't login again because of "redirected you too many times" error .

I use flask blueprint model for my app and the login part handled with flask-login.

I asked flask-login(in github : https://github.com/maxcountryman/flask-login/issues/564) .

flask : 1.1.2 Werkzeug : 1.0.1

This is part of my code related to flask-login :

@auth.route('/login', methods=('GET', 'POST'))
def login():
    if current_user.is_authenticated:
        return redirect(url_for("indexb.index", title=branding_title))
    if request.method == "POST":
        user = User.query.filter_by(username=request.form["username"]).first()
        if user and user.check_password(request.form["password"]):
            login_user(user)
            return redirect(url_for("indexb.index", title=branding_title))
        else:
            flash("invalid user Cred !")
            return redirect(url_for("auth.login", title=branding_title))

    return render_template('auth/login.html')


@auth.before_app_request
def load_logged_in_user():
    user_id = session.get('user_id')

    if user_id is None:
        g.user = None
    else:
        g.user = current_user


@auth.route('/logout')
def logout():
    session.clear()
    return redirect(url_for('indexb.index'))


def login_required(view):
    @functools.wraps(view)
    def wrapped_view(**kwargs):
        if g.user is None:
            return redirect(url_for('auth.login'))

        return view(**kwargs)

    return wrapped_view
question from:https://stackoverflow.com/questions/65933275/upgrade-to-flask-login-0-5-0-from-flask-login-0-4-1-redirected-you-too-many-time

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...