I have a flask app and want to update a value in a template periodically. This value will come from a Flask route. For example my views are defined like so:
from . import main
from flask import render_template
@main.route('/')
def index():
return render_template('index.html')
@main.route('/price')
def price():
return 5
Now my index.html:
<html>
<body>
<p id="p1">Replace this text</p>
<script>
setInterval(function(){
document.getElementById("p1").innerHTML = "some value";
}, 5000);
</script>
<p>The paragraph above was changed by a script.</p>
</body>
</html>
How can I call the /price
route from within the js and then use the returned value in id=p1
?