Flask: redirect to same page after form submission
<p>I have two forms on in my template: one, to post something and the second, to activate file deletion on the server:</p>

<pre><code>&lt;div style="margin-bottom:150px;"&gt;
    &lt;h4&gt;Delete&lt;/h4&gt;
    &lt;form method="post" action="/delete"&gt;
        &lt;div class="form-group"&gt;
            &lt;input type="hidden" name="delete_input"&gt;&lt;/input&gt;
        &lt;/div&gt;
        &lt;button type="submit" class="btn btn-danger" id="btnSignUp"&gt;Delete&lt;/button&gt;
    &lt;/form&gt;
&lt;/div&gt;

&lt;div style="margin-bottom:150px;"&gt;
    &lt;h4&gt;URLs&lt;/h4&gt;
    &lt;form method="post" action="/"&gt;
        &lt;div class="form-group"&gt;
            &lt;textarea class="form-control" rows="5" id="urls" name="url_area"&gt;&lt;/textarea&gt;
        &lt;/div&gt;
        &lt;button type="submit" class="btn btn-primary" id="btnSignUp"&gt;Urls&lt;/button&gt;
    &lt;/form&gt;
&lt;/div&gt;
</code></pre>

<p>My <code>app.py</code> looks like this:</p>

<pre><code>@app.route("/")
def main():
    return render_template('index.html')


@app.route('/', methods=['POST'])
def parse_urls():
    _urls = request.form['url_area'].split("\n")
    image_list = get_images(_urls)
    return render_template('index.html', images=image_list)


@app.route('/delete', methods=['POST'])
def delete_images():
    file_list = [f for f in os.listdir("./static") if f.endswith(".png")]
    for f in file_list:
        os.remove("./static/" + f)
    image_list = []
    conn = sqlite3.connect('_db/database.db')

    curs = conn.cursor()
    sql = "DROP TABLE IF EXISTS images"
    curs.execute(sql)
    conn.commit()
    conn.close()
    return render_template('index.html', images=image_list)
</code></pre>

<p>Two issues:</p>

<ul>
<li>I get the form resubmission message when I reload the page after submitting the form</li>
<li>I would like to have one url for everything</li>
</ul>

<p>The way I see it, I need so use redirects to avoid the duplicate submission and after calling delete, I need to redirect to index.</p>

<p>How can I do this correctly?</p>

<p>I know about <code>redirect</code> and <code>url_for</code>, but how do I redirect to the same page?</p>