0
我试图在成功登录后重定向页面,但我仍然遇到同样的问题。在烧瓶登录url重定向
我的登录代码:
@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视图。
当我进入我的登录凭据,网址重定向到http://192.168.1.109:5000/login/?next=%2Fprotected%2F
我没有完全理解的文档。有人能够更好地解释这个概念吗?我为什么得到这个?
当我尝试将它连接到我的angularjs前端时,这也会出现。
的问候,苏尼尔
你可以显示你的'flask_login'' user_loader'函数吗? – Wombatz
嗨Wombatz,对不起,迟到的回应。看起来前端存在问题(我正在使用AngularJS)。当我使用邮递员或浏览器时,登录功能完美无缺。只有当我通过应用模拟器访问它时,它才会抛出这个错误。 – galeej