0

Following is the context that contains these two variables, and is being sent for rendering through views.py in my Django application:

{"all":[{"a":1, "b":2},{"a":3, "b":4}], "columns": ["a", "b"]} 

Code inside template rendering

<table> <thead> <tr> {% for c in columns %} <td> {{ c }} </td> {% endfor %} </tr> </thead> {% for a in all %} <tr> {% for c in columns %} <td>{{ a.c }}</td> {% endfor %} </tr> {% endfor %} </table> 

Problem:

I am basically trying to render table rows in Django using the above code. But, even after the data is present, the data is not displayed in the table. Am I correctly accessing the data by writing a.c. If not, what is the correct code to get the desired output?

2
  • try to display just {{ columns }} and {{ all }}. is it work well? Commented Jun 4, 2018 at 6:03
  • 1
    When you say a.c it's trying to lookup the literal key c, not the column name like you're expecting. The best way to handle this will probably be to have all be a list of lists ("rows"), where each row has the fields in the correct order to match the table heading. Commented Jun 4, 2018 at 6:15

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.