get_at_index:0 }} the output is the first list of my Queryset:

问题描述 投票:0回答:1
Now, I would get each element of the List2

The template result is empty!

But with the following:

{% for obj in list1 %}
  <p>List1: {{ obj }}</p>
  <p>List2 element: {{ list2|get_at_index:forloop.counter0 }}
{% endfor %}

I read only the "k" name:

and with:

I receive the

list2:  <QuerySet [{'id': 1, 'idse': 1, 'prof': 5, 'product': 'test1', 'producer': 'beta'}, 
{'id': 2, 'idse': 1, 'prof': 8, 'product': 'test2', 'producer': 'alpha'}, 
{'id': 3, 'idse': 1, 'prof': 15, 'product': 'test3', 'producer': 'test'}, 
{'id': 4, 'idse': 1, 'prof': 25, 'product': 'test4', 'producer': 'test2'},
....
....
]>

Error

{'id': 1, 'idse': 1, 'prof': 5, 'product': 'test1', 'producer': 'beta'}

:

{% for obj in list1 %}
  <p>List1: {{ obj }}</p>
    {% for obj in list2|get_at_index:forloop.counter0 %}  
        {{ obj.id }},{{ obj.idse }},..
    {% endfor %}
{% endfor %}

Need 2 values to unpack in for loopI don't know if my approach is correct or not and how can I read the element value.Have you any suggestions?

{% for obj in list2|get_at_index:forloop.counter0 %}  
        <li>{{ obj }}</li>
{% endfor %}

[Django 1.11.8] The template receive by the view.py two different lists, that for semplicity: {% for obj in list1 %}

<li>id</li>
<li>idse</li>
<li>prof</li>

List1: {{ obj }}

{% for obj,value in list2|get_at_index:forloop.counter0 %}  
    <li>{{ obj }}:{{value}}</li>
{% endfor %}

List2 element: {{ list2 [

Django 1.11.8

]
python django-templates django-queryset
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.