I'm building a Flask app and I've come to the point where I'm rendering a template to display some data on a table. In this template I have a button which takes me to a view function that makes some statistical analysis on the data. After this analysis, I want to display the statistics on the same template without re-rendering it. In short terms, I want to press the button and the data to be displayed right there without reloading the page. So far, I don't know how to do that as I always return "render_template" or "redirect" from my view functions.
I was thinking if there is a way to return the data from the view function into a javascript script into the template and then this script to handle how to display them but I can't figure out how.
Edit for duplicate:
I tried the solutions suggested on the duplicate question. Specifically, I have now as a return:
return json.dumps(avg)
or
return jsonify(avg)
but now it just displays a blank page with my list (avg). What I want is not to reload the page but to display the data within the template in which I clicked the button.