0

Is it possible to access the inner loop using the key of the outer loop in the Django template as follows?

{% for a in a_list %}
    {% for b in b_list %} # ← this is a dict
            <p>{{ b.a }}</p> # ← what i wan't to do!
    {% endfor %}
{% endfor %}
MuscleBoy
  • 69
  • 2
  • 10
  • There is [no built-in method](https://code.djangoproject.com/ticket/12486) for that but you can always write your own. See https://stackoverflow.com/a/1275751/2011147 – Selcuk Dec 06 '18 at 02:49

1 Answers1

1

I think you can do it like this:

{% for a in a_list %}
    {% for key, value in b_list.items %} # ← this is a dict
            {% if key == a %}
               {{ value }}
            {% endif %}
    {% endfor %}
{% endfor %}
ruddra
  • 50,746
  • 7
  • 78
  • 101