i have the sql query like this and i want to display in my template then there is no error but my template is empty
def detail_labo(request,pk):
patient=Patient.objects.get(Idpatient=pk)
actelabo=patient.actelabo_set.values('date_examen','nom_patient').annotate(Sum('somme_labo'))
print(actelabo)
context={'patient':patient, 'actelabo':actelabo}
return render(request,'pages_t/detail_labo.html',context)
{% for labo in actelabo %}
<tr>
<td>{{labo.examen}}</td>
<td>{{labo.medecin_prescripteur}}</td>
<td>{{labo.pourcentage}}</td>
<td>{{labo.difference_labo}}</td>
<td>{{labo.somme_labo}}</td>
</tr>
{% endfor %}
Have you verified that there is data in the resultset for the query?
What does the line print(actelabo)
generate?
What do the Patient
and other model (the model referred to by the actelabo
reference variable) look like?
What does the rest of the template look like? Are there any conditions or blocks or other template elements that might be affecting this?
yes it does contain data and it looks like this
<QuerySet [
{'date_examen': datetime.date(2021, 12, 14), 'nom_patient': 4, 'somme_labo__sum': 560.0}, {'date_examen': datetime.date(2021, 12, 20), 'nom_patient': 4, 'somme_labo__sum': 19600.0}
]>
So the keys in the dict are:
date_examen
nom_patient
somme_labo__sum
That’s the data you’re passing to the template.
But your template isn’t rendering any fields by that name. The fields you’re trying to render don’t appear in the context.
thank you very much for your message and for your help