title: How can Javascript access data sent from Python Flask's render_template() function?
body: <p>Problem: I am trying to access data I send (when the user navigates to the landing page of the site) from Javascript code so I can display it when the document is ready. This data is a dataframe.</p>
  
  <p>Python Code: </p>
  
  <pre><code>from flask import Flask, render_template, jsonify
  import pandas as pd
  import numpy as np
  from pandas import DataFrame
  @app.route("/",methods = ['POST', 'GET'])
  def homeLanding():
      df = pd.DataFrame(data=[['ab1234','12:34'],['cd1234','12:36'],['ae54548','12:55'],['df59894','12:56']])
      df2 = df.to_json(orient='records')
      return render_template("index.html",someResponse=df2,namespace='/test')
  </code></pre>
  
  <p>Javascript Code:</p>
  
  <pre><code>$(document).ready(function(){
      //Convert response dataframe to variable
      console.log(someResponse);
      var x = JSON.parse(someResponse);
      //print response dataframe
      console.log(x);
      //populate table with response dataframe.
      $('#table1').DataTable({
          "destroy":true,
          "searching": false,
          "ordering": false,
          "paging": false,
          "bordering":true,
          data: x,
          columns: [
          {"title": 'ID'},
          {"title": 'Time'},
          ]
      });
  });
  </code></pre>
  
  <p>html Script:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;script src="//code.jquery.com/jquery-3.3.1.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.6/socket.io.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"&gt;&lt;/script&gt;
          &lt;script src="static/js/application.js"&gt;&lt;/script&gt;
  
          &lt;link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&gt;
          &lt;link rel="stylesheet" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css"&gt;
          &lt;link rel="stylesheet" href="static/css/application.css"&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div class="container"&gt;
              &lt;div class="container-wrapper" margin="auto"&gt;
                  &lt;table id="table1" class="display"&gt;&lt;/table&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Current Status: I have been trying several ways of passing the dataframe to render_template() but the dataframe does not seem to get sent over to the client's Javascript code or I do not know how to properly access the data from Javascript response. The dataframe does not print to the console and it does not populate table1.</p>
  
  <p>Thanks in advance.</p>