Is there a way to do something like the following in Django templates?
{% for hop in hops%}
<tr>
<td>{{ hop.name }}</td>
<td>{{ hop.mass }}</td>
<td>{{ hop."boil time" }}</td>
</tr>
{% endfor %}
The hop.”boil time” doesn’t work. The simple solution is rename the key boil_time, but I’m interested in alternatives.
The best way to get at it is to sneak the property name into another variable, like so:
In Django 0.96 (the version used by Google AppEngine) the templating language doesn’t support tuple expansion, so it’s a bit uglier:
So, taking your code, we end up with:
In Django 0.96 (the version on Google AppEnginge), this becomes:
There’s even a wordier way to get at it, using the regroup tag: