title: How to display all images in a directory with flask
body: <p>I am trying to display all images from a particular directory in static (static/plots).  Here is my python: </p>
  
  <pre><code>hists = os.listdir('static/plots')
  hists = ['plots/' + file for file in hists]
  return render_template('report.html', hists = hists)
  </code></pre>
  
  <p>and my html:</p>
  
  <pre><code>&lt;!DOCTYPE=html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;
          Store Report
      &lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      {{first_event}} to {{second_event}}
      {% for hist in hists %}
      &lt;img src="{{url_for('static', filename='{{hist}}')}}" alt="{{hist}}"&gt;
      {% endfor %}
  &lt;/body&gt;
  &lt;/html&gt;`
  </code></pre>
  
  <p>And when the template successfully renders, the templates are not fetched.  Opening the image in a new tab yields: 
  <code><a href="http://127.0.0.1:8080/static/%7B%7Bhist%7D%7D" rel="noreferrer">http://127.0.0.1:8080/static/%7B%7Bhist%7D%7D</a></code></p>
  
  <p>I imagine the problem is with this line, but I can't figure out what's correct: </p>
  
  <p><code>&lt;img src="{{url_for('static', filename='{{hist}}')}}" alt="{{hist}}"&gt;</code></p>