1

I want to iterate over 2 sets of data and display values in my template.

I have something like that:

{% for email,phone in user.email_set.all, user.phone_set.all %}
{{email}} {{phone}}

{% endfor %}

Unfortunately I get TemplateSyntaxError:

'for' statements should use the format 'for x in y'

Is there a way I can do it?

Frendom
  • 508
  • 6
  • 24
  • This looks a bit odd in the first place. What if the `email_set` contains more (or less) elements than the `phone_set`? – Willem Van Onsem Jun 11 '19 at 21:34
  • You can create a dict of { email : phone }. The way you did makes no sense. – caot Jun 11 '19 at 21:38
  • @WillemVanOnsem yea, but it doesnt matter if this sets arent equals to each other. I just want to display them in one line. I can do second loop and separately display phone and email, but they will be presented in ugly way – Frendom Jun 11 '19 at 21:59
  • Possible duplicate of [Iterating through two lists in Django templates](https://stackoverflow.com/questions/2415865/iterating-through-two-lists-in-django-templates) – hoefling Jun 11 '19 at 22:22

0 Answers0