title: Iterating over a list of URLs in an HTML template using Python/Flask
body: <p>This seems like a very basic problem but I can't figure it out. I'm passing a list of URLs into an HTML page and trying to print each one out in an href tag. I'm using Flask to run the test server, and can confirm that the variables are being passed in correctly (I can print out the entire list or elements from it).</p>
  
  <p>My app route:</p>
  
  <pre><code>import doaudit # separate Py script that gets these urls
  
  @app.route('/audit', methods = ['GET'])
  def audit():
      return render_template('audit.html', listOfUrls = doaudit.listOfUrls)
  </code></pre>
  
  <p>My template:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Data Audit&lt;/title&gt;   
  &lt;/head&gt;
  &lt;body&gt;
  
          {% for url in listOfUrls %}        
          &lt;script language="JavaScript"&gt;
              document.write( "&lt;a href=\"" + url + "\"&gt;linktext&lt;/a&gt;" );
          &lt;/script&gt;
          {% endfor %}
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I've tried variations on:</p>
  
  <pre><code>document.write( "&lt;a href=\"" + '{{ listOfUrls[i] }}' + "\"&gt;linktext&lt;/a&gt;" );
  </code></pre>
  
  <p>and iterating over all the i's but that doesn't work either.</p>
  
  <p>The length of the list can vary, so I need an iterative solution. Thanks in advance.</p>