title: Update a variable dynamically in flask
body: <p>I m working with flask and need to make a python variable appear on a HTML page &amp; update it in real time without the need to refresh . i have searched but couldn't do it. To find a solution the simple way i have created in the python script a time variable that should be updated in the page dynamically.Here is my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script&gt;
      $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
      (function(){
          $.getJSON(
              $SCRIPT_ROOT+"/get_data",
              function(data) {
                 $("#testt").text(data.time);
              }
          setInterval(arguments.callee, 1000);
          );
      });
  &lt;/script&gt;
  &lt;span id="testt"&gt;?&lt;/span&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import datetime
  from flask.app import Flask
  from flask.json import jsonify
  
  app=Flask(__name__)
  
  @app.route('/get_data', methods=['GET'])
  def get_data():
      return jsonify(time=str(datetime.datetime.now().time()))
  if __name__=="__main__":
      app.run(debug = True, host='0.0.0.0')      </code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>EDIT:</strong> In my solution the time only updates when i refresh the page .  want it to update in real time.</p>