@app.route('/register', methods=['GET', 'POST'])
def register():
    if request.method == 'GET':
        if 'wantsurl' in request.args:
            qs = request.args['wantsurl']
return render_template('register.html', wantsurl=qs)
if request.method == 'POST':
    if 'wantsurl' in request.form and everything_else_ok:
        return redirect(request.form['wantsurl'])
Flask/Werkzeug, how to return previous page after login