0

My webapp has two pages: home and maps. Clicking on either button on home should redirect to maps (with different parameters). However, on clicking Flask routes me to '/' (home). I tried getting around this with a redirect, but then the form data wasn't preserved.

Here is the relevant code: home.html

    <form method="POST" href="/maps">
    <div class="next_btns">
            <button class="hidden_btns searchBtn btn-primary" type="submit" name="spot" id="spot_btn">Spot</button>
            <button class="hidden_btns searchBtn btn-primary" type="submit" name="event" id="events_btn">Events</button>
        </div>
        </form>

app.py

@app.route('/', methods=['GET'])
def home_page():
    if request.method == 'GET':
        return render_template('home.html')

@app.route('/maps', methods=['GET', 'POST'])
def maps():
    if request.method == 'GET':
        return render_template('404.html')
    elif request.method == 'POST':
        if 'spot' in request.form:
            return render_template('maps.html', filter='spot')
        elif 'event' in request.form:
            return render_template('maps.html', filter='event')
Josh Friedlander
  • 10,870
  • 5
  • 35
  • 75

1 Answers1

1

Try changing your form to use action instead of href.

<form method="POST" action="/maps">
  <div class="next_btns">
    <button class="hidden_btns searchBtn btn-primary" type="submit" name="spot" id="spot_btn">Spot</button>
    <button class="hidden_btns searchBtn btn-primary" type="submit" name="event" id="events_btn">Events</button>
  </div>
</form>
Tim Thompson
  • 301
  • 2
  • 7