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ビューを持っています。
私は自分のログイン資格情報を入力すると、URLが、私は完全にドキュメントを理解していなかったhttp://192.168.1.109:5000/login/?next=%2Fprotected%2F
にリダイレクトします。誰かがこの概念をよりよく説明できるでしょうか?なぜ私はこれを取得していますか?
これは私がanglejsフロントエンドに接続しようとしているときにも起こります。
よろしく、 スニル
あなたの 'flask_login'' user_loader'関数を表示できますか? – Wombatz
こんにちはWombatz、後半の返事には申し訳ありません。フロントエンドに問題があるようです(私はAngularJSを使用しています)。郵便配達員やブラウザを使用すると、ログインは完全に機能します。これは、私がアプリケーションエミュレータからアクセスするときだけ、このエラーをスローします。 – galeej