1👍
✅
You can just use zip() in your view.
listas = zip(lista_completa, lista_completa2)
return render(request, template.html, {'listas': listas})
Then just unpack the tuple over each oteration using two variables in a for loop.
{% for pregunta, respuesta in listas %}
# pregunta.show (or whatever your attribute for pregunta is)
# respuesta.show
{% endfor %}
Saludos!
0👍
Django does not use Jinja2 templates by default. Unless you specifically configured Django to use Jinja2, you’re using the Django template language (which has a very similar syntax).
Django’s template engine doesn’t have any nice way to do this. You just need to zip
the two QuerySet
s before passing them into the template:
return render(request, 'todo.html', {
'preguntas_y_respuestas': zip(lista_completa, lista_completa2)
})
In your template, you can iterate over the pairs of objects:
{% for pregunta, respuesta in preguntas_y_respuestas %}
...
{% endfor %}
- Sign up django with cbv and AbstractUser model image error
- Django: icontains over unicode string
- Grouping QuerySet in Django
- SNS notifications to Browser
Source:stackexchange.com