How to link to another page using a POST form and <a> in Flask

Viewed 58
<div class="dropdown">
    <button class="dropbtn"><h2>Please select your device <i class="fa fa-caret-down"></i></h2> </button>

    <div class="dropdown-content">
        {% for n in range(devicesFiles|length) %}
        <form action={{url_for("annotator")}} method='POST'>
        <a name="deviceID"> {{devicesFiles[n]}} </a></form>
        {% endfor %}
    </div>
</div>


@app.route("/annotator/", methods=['POST'])
def annotator():
    return render_template("annotator.html")

I want to be able to go to url_for("annotator") when I click one of the dropdown menu boxes and send the name variable in post. Maybe there is an easier way than to use a tag. Thank you!

enter image description here

1 Answers

Try this:

<div class="dropdown">
    <button class="dropbtn"><h2>Please select your device <i class="fa fa-caret-down"></i></h2> </button>

    <div class="dropdown-content">

        <form action={{url_for("annotator")}} method='POST' id='annotator'>
        <select id='annotate_select' form='annotator'>
        {% for n in range(devicesFiles|length) %}
        <option value={{devicesFiles[n]}}>{{devicesFiles[n]}}</option>
        {% endfor %}
        </select>
        </form>

    </div>
</div>
Related