Hi Luca,

As far as I'm able to understand you need to print the elements in the 
lista array corresponding to the current forloop.counter0, if this is the 
case then you can do:

{% load index %}
{{ lista|index:forloop.counter0 }} // this will print the element in the 
lista array corresponding to the current forloop counter

Note: I have created the custom template filter like:

from django import template
register = template.Library()

@register.filter
def index(indexable, i):
    return indexable[i]


Docs: Django 
<https://docs.djangoproject.com/en/2.2/howto/custom-template-tags/> (For 
creating the custom template filter)
Example: StackOverflow <https://stackoverflow.com/a/29664945/10353116>

--
Thanks
Pradeep Sukhwani


On Friday, October 4, 2019 at 8:21:44 PM UTC+5:30, Luca Bertolotti wrote:
>
> from the view i give to the template the following variables
>
> selezione = Dbasedett.objects.filter(idbase=mod_id, revdbase=rev_test)
> lista = ['test', 'test_one']
>
> Than i return render(.........{'selezione':selezione, 'lista':lista}
>
> In the form i need to do this:
>
> <table>
>         
>         {% for dati in selezione %} 
>             <tr class={% cycle 'odd' 'even' %}>
>             <td>{{ dati.pos }}</td> <td>{{ dati.matr }}</td> <td>{{ 
> lista.forloop.counter0 
> }}</td>
>             </tr>
>         {% endfor %}
>
> But {{ lista.forloop.counter0 }} is empty 
>
> Any help
>
> thanks
>        
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a2fd7244-0463-4bb7-b01a-244c250a119c%40googlegroups.com.

Reply via email to