1👍
✅
In your view, just add .values_list('name', flat=True)
to your queryset. Now you are passing a list of item names to your template.
Other options:
- Use a for loop to iterate over items.
- Make a custom template tag.
0👍
If your just want to iterate the names in items:
{% for item in items %}
<p>name: {{item.name}}</p>
{% endfor %}
- [Answer]-Do debug messages being displayed on production server?
- [Answer]-Accessing a Form's cleaned data from a signals callback?
0👍
You can iterate over the items
like that, in a for
:
{% for item in items %}
<p>Name: {{ item.name }}</p>
<p>Value: {{ item.value }}</p>
{% endfor %}
You can’t “create” variables in the Django Template Engine, but you can do it in your View:
items_names = [x['name'] for x in items]
And then access the items_names
in your template.
- [Answer]-Django – There was a decent size cascade delete, now how do I fix this?
- [Answer]-Receiving duplicate signals. How to search for the cause?
Source:stackexchange.com