title: Reading from database and passing to JavaScript in Flask
body: <p>Completely new to Python and Flask. Trying to read from database and pass the data to Javascript. Pulling my hair out trying to get it working, as I assume it's something small</p>
  
  <p>In my python script I have:</p>
  
  <pre><code>@app.route('/report')
  def test():
      db = get_db()
      cur = db.execute('select * from emails where id=1')
      emails = cur.fetchall()
      print emails
      return render_template('report.html', name=links, emails=emails)
  </code></pre>
  
  <p>and then in my javascript I have:</p>
  
  <pre><code>{% for entry in emails %}
      var getEmail = {{entry.1}}
      window.alert(getEmail);
      emailArray.push(getEmail)
  {% endfor %}
  </code></pre>
  
  <p>print emails is outputting <code>[(1, u'e')]</code>, which is correct, but the <code>window.alert</code> is giving me "undefined". If I change it to <code>var getEmail = {{entry.0}}</code> it gives me the correct ID value from the database. Can anyone point me to where I'm going wrong?</p>