title: Flask send_file is sending old file instead of newest
body: <p>I have a flask app where using one Flask <code>route</code> the server creates a csv file and saves it to the server. Using a generated button on the client page, another Flask <code>route</code> is triggered to get the most recent file, move it to a tmp folder and send that file to the user using <code>send_file</code>. </p>
  
  <p>Right now, when I run the process the first time and download the file, all works as expected. However, the second time I run the process, it serves me the old CSV instead of the newly generated one. This continues until I hit the refresh button on my browser.</p>
  
  <p>The following is my app code:</p>
  
  <pre><code>from flask import Flask, render_template, flash, redirect, request, url_for, Response, send_file
  import os
  import time
  import shutil
  import glob
  
  app = Flask(__name__)
  app.config['SECRET_KEY'] = 'secret!'
  
  @app.route('/')
  def index():
      return render_template('index.html')
  
  
  @app.route('/downloadcsv')
  def downloadcsv():
      current = os.getcwd()
      try:
          list = glob.glob('{}/*.csv'.format(current))
      except:
          print('No file found')
      basename = os.path.basename(os.path.normpath(max(list, key=os.path.getctime)))
      shutil.move(basename, './tmp/{}'.format(basename))
      return send_file('./tmp/{}'.format(basename), as_attachment=True)
  </code></pre>
  
  <p>In case it is needed, the following is the JS code which "generates" the download button:</p>
  
  <pre><code>var download = '&lt;div id="downloadsection" class="container-contact100-form-btn"&gt;&lt;a href="/downloadcsv"&gt;&lt;button id="download" class="contact100-form-btn"&gt; &lt;span&gt;DOWNLOAD CSV&lt;/span&gt;&lt;/button&gt;&lt;/a&gt;&lt;/div&gt;';
  </code></pre>
  
  <p>Please also let me know if I am over complicating the download process...</p>
  
  <p>Thanks!!</p>