This view receives the ?next= argument when making a GET request but once the user makes a POST request to the same view the argument is lost. The examples I've seen don't explicitly pass on the query arguments but seem to be able to retain them and get them in the following POST request.
@blueprint.route("/login", methods=["GET", "POST"])
@logout_required()
def login():
form = LoginForm()
#1
print("NEXT:", request.args.get("next"))
if form.validate_on_submit():
u = User.query.filter_by(username=form.username.data).first()
if u and u.check_password(password=form.password.data):
if u.is_active():
#2
print("NEXT:", request.args.get("next"))
login_user(u, remember=form.remember.data)
next_url = request.args.get("next")
if not next_url or url_parse(next_url).netloc != "":
next_url = url_for("main.index")
return redirect(next_url)
else:
flash("This account has been disabled", "error")
else:
flash("Invalid password or username.", "error")
return render_template("auth/login.html", form=form)