0
<table class="table">       
    <tr>
        {% for item in summary.titles %}
            <th>{{ item }}</th>
        {% endfor %}
    </tr>
    <tr>
        {% for title in summary.titles %}
            <td> {{ summary.data[title] }}</td>
        {% endfor %}
    </tr>
</table>

Is it possible to get data in a similar way?

Exception Value:

Could not parse the remainder: '[title]' from 'summary.data[title]'

var summary = {
    data:{
        title1: 1,
        title2:2
    }, 
    titles: [title1, title2]
}
jape
  • 2,861
  • 2
  • 26
  • 58
Lola
  • 2,591
  • 6
  • 24
  • 49
  • Too less context to answer this. What data are you sending to this template? can you show any example? – Arpit Solanki Aug 21 '17 at 13:35
  • Possible duplicate of [Performing a getattr() style lookup in a django template](https://stackoverflow.com/questions/844746/performing-a-getattr-style-lookup-in-a-django-template) – drdaeman Aug 21 '17 at 13:36
  • Also, possible duplicate of [Django template - dynamic variable name](https://stackoverflow.com/questions/17148544/django-template-dynamic-variable-name) – drdaeman Aug 21 '17 at 13:36
  • @ArpitSolanki i try to add data – Lola Aug 21 '17 at 13:38
  • If you directly use `{{ title }}` It would work Why are you using array/getattr style – Arpit Solanki Aug 21 '17 at 13:39
  • Have you tried this: `{% for title in summary.titles %}{{ data.title }}{% endfor %}` ?? – nik_m Aug 21 '17 at 14:23

0 Answers0