首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >flask-login中的url重定向

flask-login中的url重定向
EN

Stack Overflow用户
提问于 2016-07-14 23:18:59
回答 1查看 682关注 0票数 0

我试图在成功登录后重定向页面,但我总是遇到同样的问题。

我的登录码:

代码语言:javascript
复制
@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前端时,也会出现这个问题。

向您致敬,Sunil

EN

回答 1

Stack Overflow用户

发布于 2017-07-15 19:56:16

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

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38378102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档