title: Calling a Javascript function from flask / python
body: <p>I know Python very well, but I'm new to web-stuff and JavaScript. I found a post about <a href="https://stackoverflow.com/questions/30899484/python-flask-calling-functions-using-buttons">Calling a python function from button on website (Flask)</a>.</p>
  
  <p>I want to do the following: I want to add a new row to an HTML table. The data will be coming from Python. I already found out that refreshing the site isn't a good way to do it, instead it seems JavaScript should be used. Say I have the following HTML code:</p>
  
  <pre><code>&lt;table class="table" id="myTable"&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th colspan="2"&gt;This is a table&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;entry 1&lt;/td&gt;
        &lt;td&gt;entry 2&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;script src="js/scripts.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>and in the scripts.js I have the following function (from the linked post):</p>
  
  <pre><code>function appendRow(table_id) {
    var table_ref = document.getElementById(table_id).getElementsByTagName('tbody')[0];
    var new_row = table_ref.insertRow(table_ref.rows.length);
    var new_cell = new_row.insertCell(0);
    var new_text = document.createTextNode('New row');
    new_cell.appendChild(new_text);
  }
  </code></pre>
  
  <p>Now disregarding the details how the function works / what can be optimized etc. my real question is: How can I call this function from Python / flask?</p>
  
  <p>Additionally: How can I pass data (say a JSON-structure) to the JavaScript function?</p>
  
  <p>Many thanks in advance!</p>