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?
{{ columns }}and{{ all }}. is it work well?a.cit's trying to lookup the literal keyc, not the column name like you're expecting. The best way to handle this will probably be to haveallbe a list of lists ("rows"), where each row has the fields in the correct order to match the table heading.