Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass json array to html page via flask render_template

I’m working on attendance monitoring, where each student attendance status will be captured via API response in flask and need to show the response in dashboard format.

Below the sample response we get –

[
{"StudentName":"Name1", "Status":"Present"},
{"StudentName":"Name2", "Status":"Absent"}
]

I’m able to capture individual student details using array[0] and passing only 1 value to html page via flask render_template().

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How to pass the array like structure to html page and show the status of each student ?

>Solution :

Did you tried to simply pass the entire array of dictionaries?

return render_template("page.html", attendance=array_name)

Then, in the jinja2 template you can loop through it in order to display the information.

{% for student in attendance %}

<p>{{ student['StudentName'] }}</p>
<p>{{ student['Status'] }}</p>

{% endfor %}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading