[Fixed]-Django – Get element within template without field name

1👍

There is no way to do this in django templates (get a field using a dynamic name). You need to prepare your data in python, so that in the template you would have a list of field values matching the columns. The easiest way to accomplish this is to simply use the values_list queryset method:

data = Car.objects.values_list()

And then just iterate the list in the template (you might want to change variable names here):

{% for field_value in value %}
  <td>{{ value }}</td>
{% endfor %}

(this replaces the second internal for)

👤noamk

Leave a comment