Home > front end >  Django views not able to show the dictionary object data
Django views not able to show the dictionary object data

Time:01-23

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

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

CodePudding user response:

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 %}

CodePudding user response:

Just use mm.month

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

Also there must be space before and after % in your templates. There is no space in your endfor

  •  Tags:  
  • Related