Flask: How to print variable to web page using ajax

Solution
from flask import Flask, jsonify, render_template


app = Flask(__name__)


def track():
    total = 0
    average = 0

    while True:
        if 1 == 1:
            average += 2

        total += 1
        yield dict(total=total, average=average)


@app.route("/")
def home():
    return render_template("theme1.html")


@app.get("/update")
def update():
    return jsonify(next(gen_total))


if __name__ == "__main__":
    gen_total = track()
    app.run(debug=True)



  Document