title: How to provide temporary download url in Flask?
body: <p>Currently, my <code>index.html</code> file contains</p>
  
  <pre><code>&lt;a href="static/file.ext"&gt;Download&lt;/a&gt;
  </code></pre>
  
  <p>I want to change this so that the download url is only valid for a certain time. For example, how would I change it to</p>
  
  <pre><code>&lt;a href="get_file?file=file.ext&amp;token=TEMPORARYTOKEN"&gt;Download&lt;/a&gt;
  </code></pre>
  
  <p>In my Flask file, I could then have</p>
  
  <pre><code>@app.route('/get_file')
  def get_file():
      filename = request.args.get('file')
      token = request.args.get('token')
      if token is valid: # what can be done here
          return send_from_directory('static', filename)
  </code></pre>
  
  <p>How can I generate and handle the token? Or am I approaching this completely wrong?</p>