Flask 登录中的url重定向

Flask 登录中的url重定向,flask,flask-login,Flask,Flask Login,我试图重定向成功登录后的页面,但我一直遇到相同的问题 我的登录码: @app.route('/login/', methods = ['GET', 'POST']) def login(): if request.method == 'POST': #data = request.get_json() #app.logger.debug(data) auth = g.couch.get('_design/authentication')

我试图重定向成功登录后的页面,但我一直遇到相同的问题

我的登录码:

@app.route('/login/', methods = ['GET', 'POST'])
def login():
    if request.method == 'POST':
        #data = request.get_json()
        #app.logger.debug(data)
        auth = g.couch.get('_design/authentication')
        authView = ViewDefinition('_design/authentication','authentication',auth['views']['authentication']['map'])
        for row in authView():
            if request.form['username'] == row.value['username'] and request.form['password'] == row.value['password']:
                authUser = userModel.User(row.value)
                app.logger.debug(row.value)
                authUser.authenticated = True;
                flask_login.login_user(authUser,remember = True)
                next = request.args.get('next')
                return redirect(next or url_for('/protected/')) 
    return render_template('sampleLoginPage.html')

@app.route('/protected/', methods = ['GET'])
@flask_login.login_required
def protected():
    app.logger.debug("Successful Login")
    app.logger.debug(flask_login.current_user.userID)
    return Response(json.dumps({'message' : '\'You\'re logged in so you can see this page'+flask_login.current_user.username}), mimetype = 'application/json')
html模板获取用户名和密码。我有一个认证用户的couchdb视图

当我输入登录凭据时,url重定向到
http://192.168.1.109:5000/login/?next=%2Fprotected%2F

我没有完全理解文档。有人能更好地解释这个概念吗?为什么我会得到这个

当我尝试将它连接到angularjs前端时,也会出现这种情况

问候,,
苏尼尔

我也有这个问题。当我从声明中删除
@login\u required
时,重定向按预期工作。

能否显示您的
flask\u登录
user\u loader
功能?您好,Wombatz,很抱歉响应太晚。前端似乎有问题(我使用的是AngularJS)。当我使用邮递员或浏览器时,登录效果非常好。只有当我通过应用程序模拟器访问它时,它才会抛出这个错误。因为它不再需要身份验证。