As far as I know you can't do it directly in the templating system Yo could write a template tag as described here
https://stackoverflow.com/questions/2894365/use-variable-as-dictionary-key-in-django-template/10700142#10700142 or use a different data structure, for example each row as a list of the values in the order that they should appear On Wed, Jun 13, 2018 at 4:54 PM Mikkel Kromann <[email protected]> wrote: > Dear Django users. > > Thanks to the good advice of many people on this list, I've managed to > create some nice generic class based views that work simultaneously with > many models. > The models may differ from each other with regards to the number of > columns in their data tables as well as the naming of the columns. > In order to use the same ListView template for many models, I will need to > iterate not only over the rows of the queries, but also the columns. > > I managed to pass a field_list into the context_data - it works as it > shows nicely in the table headers. > However, when I iterate over the rows of the query result table, I'm not > able to pinpoint the fields of the data row using the field iterator. > > My template.html is: > <table> > <tr> > {% for fields in field_list %} > <th>{{field}} > {% endfor %} > {% for row in row_list %} > <tr> > {% for field in field_list %} > <td>{{row.field}} > {% endfor %} > {% endfor %} > </table> > > > Besides trying with {{row.field}}, I've tried with {{row}}.{{field}}, as > well as {{ row.{{field}} }} (yeah, long shot ...) > > Any ideas, or should I try to create an entirely different data structure > in my view, which can be parsed more easily by Django templates? > > > cheers + thanks, Mikkel > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/c9e29d66-f93c-4fc4-ae9f-dbeae93a2e45%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/c9e29d66-f93c-4fc4-ae9f-dbeae93a2e45%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei2wQ4h-WFRy%3Dv_xqa6Bxi_Y_k8Z8qDvZpu3X2arh2ndQA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

