title: Use context var to access attribute in django template
body: <p>I'm building a template to render several models in the same table format. I use a class based listviews to access the model.</p>
  <p>I've also overwritten the context to give the fields needed for each type of model :</p>
  <p>views.py</p>
  <pre><code>class ProductListView(ListView):
      template_name = 'myApp/table.html'
      model = Product
  
      def get_context_data(self, **kwargs):
          context = super().get_context_data(**kwargs)
          context['fields'] = ['name', 'product_type', 'cost', 'margin']
          return context
  </code></pre>
  <p>In the template, I'd like to loop through the given fields, by doing :</p>
  <pre><code>        {% for element in object_list %}
          &lt;tr&gt;
              {% for field in fields %}
              &lt;td&gt;{{ element.field }}&lt;/td&gt;
              {% endfor %}
          &lt;/tr&gt;
          {% endfor %}
  </code></pre>
  <p>But it does not display anything.
  I've read in the documentation (<a href="https://docs.djangoproject.com/en/3.1/ref/templates/language/" rel="nofollow noreferrer">https://docs.djangoproject.com/en/3.1/ref/templates/language/</a>) that :</p>
  <blockquote>
  <p>Note that “bar” in a template expression like {{ foo.bar }} will be interpreted as a literal string and not using the value of the variable “bar”, if one exists in the template context.</p>
  </blockquote>
  <p>and I understand what I'm doing wrong but I can't figure out how to display this field. I can't just explicitely write the field names in the template because I want this template to be able to handle differents models.</p>
  <p>Is there any way to loop through the given fields ?</p>