A
A
ArtiomK2019-10-31 10:20:43
Python
ArtiomK, 2019-10-31 10:20:43

How to force the page to open in the same browser tab when a Flask Forms POST form button is clicked?

I have a Form with a POST method, I want that when the form button is clicked, the page opens in the same tab, but it opens in a new tab.
It is noteworthy that if you then go to a new tab and click the same button on the same form, the new page will be loaded in the same tab, and not in a new one.
How to solve this problem? Everywhere I find that the target tag is responsible for the opening.
Flask code:

@app.route('/wifi', methods=["GET", "POST"])
def wifi():
    result_dict = None
    pic_end = ""
    if request.method == 'POST':
        start_date = request.form['calendar1']
        end_date = request.form["calendar2"]
        period = request.form["period"]
        # do some work here ...

    return render_template("test_wifi.html", result_dict=result_dict, wifipic="wifi" + pic_end)

HTML code
<form action="" class="ordinary_form" id="wifi_form">

    <label for="calendar1"> Choose period start: </label>
    <input type="date" name="calendar1" id="calendar1" required> <br> <br>
    <label for="calendar2"> Choose period end: </label>
    <input type="date" name="calendar2" id="calendar2" required></p>
    <label for="period"> Step size: </label>
    <select required name="period" id="period">
        <option value="0">Day</option>
        <option value="1">Week</option>
        <option value="2">Month</option>
    </select>
    <br><br>


    <input target="_self" type="submit" value="SEND" formtarget="{{url_for('wifi')}}" formmethod="post" onclick="loading();">
</form>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Zubenko, 2019-11-01
@ArtiomK

Is this a must???
If you simply write in the form
and make the button like this:
Perhaps your issue will be resolved.
Here you need to understand what you get as a result instead of {{url_for('wifi')}}
Probably in one case you have some value in this data, and in another case another.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question