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

Django views not able to show the dictionary object data

I have the below queryset

   query_data= <QuerySet [{'month': datetime.date(2022, 1, 1), 'count': 9}, {'month': datetime.date(2021, 12, 1), 'count': 9}]>

But when I try to do in views

  {% for mm in query_data %}
             <span>{{mm['month'] | date: 'F' }}</span>
 {%endfor%}

It is not showing the data

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

but if I did <span>abcd</span> it is showing the abcd

>Solution :

In the template you have to use the dot-notation to access dictionary keys:

{% for mm in query_data %}
  <span>{{ mm.month | date: 'F' }}</span>
{% 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