Flask 没有重定向到 "next" 查询字符串

Flask not redirecting to "next" query string

下面是我的登录功能的代码(简化版)。
我正在尝试从 url 获取“下一个”参数以将用户重定向到。但它不起作用。

@bp.route('/login', methods=['GET', 'POST'])
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.dashboard'))

    if request.method == 'POST':
        form_data = request.form
        email = form_data.get('email')
        password = form_data.get('password')
        ... (Assume here that the user logged in)
        login_user(user, remember=True)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('main.dashboard')
        return redirect(next_page)
    return render_template('auth/login.html', title='Login')

在上面的代码中,next_page总是空的。谢谢你的帮助。

问题是 post 请求中没有传输“下一个”参数。我最终在登录页面上做了这样的事情:

      <!-- Hidden input to store the next argument -->
      <input
          type="hidden"
          name="next"
          value="{{ request.args.get('next', '') }}"
      />

在 Flask 路由中,我从以下位置检索下一个参数: next_page = request.args.get('next')

愚蠢的错误,我的错。