title: Prevent duplicate form submissions while awaiting a response Flask Python
body: <p>I am running a large request via API and massaging some data before the user sees it. I am looking to prevent the user from clicking the download button while all this information is processed. What would be the best way to accomplish this through a Flask Form?</p>
  <p>Here is my HTML:</p>
  <pre><code>&lt;form method=&quot;POST&quot;&gt; 
            &lt;button type=&quot;submit&quot; name=&quot;download&quot; value=&quot;download&quot; class=&quot;button is-primary is-light&quot;&gt;Download&lt;/button&gt;
            {% if error_statement %}
                &lt;article class=&quot;message is-danger&quot;&gt;
                  &lt;div class=&quot;message-body&quot;&gt;
                    {{ error_statement }}
                  &lt;/div&gt;
                &lt;/article&gt;
                {% endif %}
          &lt;/form&gt;
  </code></pre>
  <p>Here is my Flask Form:</p>
  <pre><code>from datetime import date
  import pandas as pd
  from flask_wtf import FlaskForm
  from wtforms import *
  from flask import (
      Flask,
      g,
      redirect,
      render_template,
      request,
      session,
      url_for,
      flash,
      Response
  )
  
  
  app = Flask(__name__)
  app.secret_key = 'secret'
  
  
  @app.route('/home', methods=[&quot;POST&quot;, &quot;GET&quot;])
  def home():
  class MyForm(FlaskForm):
      submit = SubmitField('Download')
  if request.method == 'POST':
      form = MyForm() 
      if request.form['download'] == 'download':
          #At this point I have code where I call a bunch of APIs and convert data to a CSV file
          #This process takes anywhere between 1-3 minutes to complete
          if not final_df.empty:
               today = date.today()
               return Response(final_df.to_csv(index=False, header=True), mimetype=&quot;text/csv&quot;, headers={&quot;Content-disposition&quot;: &quot;attachment; filename=export&quot; + today.strftime(&quot;%Y/%m/%d&quot;) + &quot;.csv&quot;})
         else:
              error_statement = 'Something Went Wrong Please Try Again'
              return render_template(&quot;login.html&quot;, error_statement=error_statement)
      return render_template('home.html', form=form)
  return redirect(url_for('login'))
  </code></pre>
  <p>Can anyone provide guidance on how to prevent the user from clicking the download button while my data is processed?</p>