[Answered ]-Django: data from context not displaying in template

1👍

When you called .values() you changed objects to QuerySet of directories with only course key and its value under field with that name. Basically it looks like this:

<QuerySet [{"course": "some value"}, {"course": "another value"}, {"course": "another value"} {...}]>

Then you make some more stuff and you try to operate them as they were objects. They are not the objects you want. Just to see what’s there try changing that loop to:

{% for course in sorted_courses %}
    <h1>{{ course }}</h1>
{% endfor %}

And I think you will understand the rest. You can always call the dictionary values inside the loop. Seeing what you have done I assume you may try:

{{ course.course }}
# or
{{ course.count }}

But I don’t think this was what you wanted. If you want to stay with database objects, use .filter() or .order_by() methods. But remember, that empty .filter() method does literally nothing.

Leave a comment