2👍
✅
Your code is:
context['category'] = Category.objects.all()
So it should be:
context['categories'] = Category.objects.all()
And in your template:
{% for category in categories %}
{{ category.name }}
{% endfor %}
The output you got in your test makes sense:
[<Category: Something not so interesting>]
it’s an array with only one entry, this entry is an object of the class Category, and the string representation of it is “Something not …”
0👍
You need to iterate over the category, since it’s queryset. E.g. in your template, you can do
<ul>
{% for c in category %}
<li> {{ c }} </li>
{% endfor %}
</ul>
- [Answered ]-Django: How do I use Cache Machine to cache a model that uses GeoManager?
- [Answered ]-Django and formsets
- [Answered ]-Django – clean() with hidden form
0👍
category
in template is queryset ( list of objects) not one single object. You need to iterate over it as
{%for c in category %}
{{c.id}} : {{ c.other_attribute }}
{%endfor%}
- [Answered ]-Display JSON as template list in django
- [Answered ]-Swampdragon settings.js
- [Answered ]-Save uploaded files in subfolder depending on request
- [Answered ]-Django Admin: variables/constants inside Django Admin that can be changed
Source:stackexchange.com