After a query is executed in my collection named 'patients' in mongodb: I have this code as a result that is named patient_doc
:
{ "_id" : "5576ee2e1a6d6d0d9b879095", "date_of_birth" : "29/06/2015", "diagnosis" : "Mamografia", "doctor_id" : "554b6e791a6d6d34cc3272f7", "name" : "Xona", "sex" : "Female", "surname" : "Krasniqi" }
{ "_id" : "5576ee2e1a6d6d0d9b879095", "date_of_birth" : "29/06/2015", "diagnosis" : "Ekografia", "doctor_id" : "554b6e791a6d6d34cc3272f7", "name" : "John", "sex" : "Male", "surname" : "Esma" }
I render a template that contains a table:
return render_template('patient-record.html', patient_doc=doc)
In the browser i have only one patient displayed , how can i use jinja syntax to view all results. I mean how can I do a loop that will display data for each patient in my case. I tried {% for patient_doc in patient_doc %}
but no result.
Html file named patient-record.html contain this code:
<table class="patient-view-table">
<tr>
<td class="property-name-col">Name:</td>
<td class="property-value-col">{{ patient_doc.name }}</td>
</tr>
<tr>
<td class="property-name-col">Surname:</td>
<td class="property-value-col">{{ patient_doc.surname }}</td>
</tr>
<tr>
<td class="property-name-col">Sex:</td>
<td class="property-value-col">{{ patient_doc.sex }}</td>
</tr>
<tr>
<td class="property-name-col">Date of birth:</td>
<td class="property-value-col">{{patient_doc.date_of_birth}}
</td>
</tr>
<tr>
<td class="property-name-col">Diagnosis:</td>
<td class="property-value-col">{{ patient_doc.diagnosis }}</td>
</tr>
</table>
Can any body help me to solve this?
Just don't duplicate the variable name
patient_doc
in the for loop.Do like this:
{% for patient in patient_doc %}
Example:
And if the result is a list i think the name of the variable should be
patients_doc
Example: