Flask对重定向的疑虑

时间:2014-10-30 08:58:47

标签: python flask

我正在关注本教程here。登录页面显示登录页面。当我单击任何提供程序并单击提交按钮时,页面将重定向回登录页面。我在这做错了什么?我在views.py页面中有以下代码

@app.route('/login', methods=['GET', 'POST'])
@oid.loginhandler
def login():
  if g.user is not None and g.user.is_authenticated():
    return redirect(url_for('index'))
  form = LoginForm()
  if form.validate_on_submit():
    session['remember_me'] = form.remember_me.data
    return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
  return render_template('login.html',
                       title='Sign In',
                       form=form,
                       providers=app.config['OPENID_PROVIDERS'])

@oid.after_login
def after_login(resp):
    if resp.email is None or resp.email=="":
            flash('Invalid login. Please try again')
            return redirect(url_for('login'))
    user=User.query.filter_by(email=resp.email).first()
    if user is None:
            nickname= resp.nickname
            if nickname is None or nickname == "":
                    nickname=resp.email.split('@')[0]
            user= User(nickname=nickname, email=resp.email)
            db.session.add(user)
            db.session.commit()
    remember_me=False
    if 'remember_me' in session:
            remember_me=session['remember_me']
            session.pop('remember_me', None)
    login_user(user, remember = remember_me)
    return redirect(request.args.get('next') or url_for('index'))

1 个答案:

答案 0 :(得分:1)

您需要设置应用配置

app.config['SECURITY_POST_LOGIN_VIEW'] = '/post_login_page'
app.config['SECURITY_POST_REGISTER_VIEW'] = '/register_complete'