3

Please see the following the code:

{% for row in df_src.iterrows %}
   <tr >
    <td><input type="checkbox"></td>                              
    {% for col in columns %}
      <td  class="redrow">{{row.1.col}}</td>                                  
    {% endfor %}                                                               
   </tr>
{% endfor %}

Here in {{row.1.col}} where col can be any value like NAME, PHONE, etc. When I access it like {{row.1.PHONE}} I get the value in html, however when I access it like {{row.1.col}} nothing is shown in html.

Faizan Ali
  • 853
  • 2
  • 14
  • 30

1 Answers1

5

You cannot access it that way, djangos template language does not allow that. See this post that @BearBrown mentioned in his comment.

You could write your own custom template filter like this answer shows:

from django.template.defaulttags import register
...
@register.filter
def get_item(dictionary, key):
    return dictionary.get(key)
Ralf
  • 14,947
  • 4
  • 39
  • 61