google app engine - Iterate over object in Jinja2? -
i'm using jinja2 on google app engine. have listview renders generic template. @ moment, i'm not sure want display, want display each attribute of model.
is there way iterate on object output each 1 in table cell?
for example:
{% record in records %} <tr> {% attribute in record %} <td>{{ attribute }}</td> {% endfor %} </tr> {% endfor %}
any advice appreciated. thanks
this trick in simple python code:
for attribute in record.properties(): print '%s: %s' % (attribute, getattr(record, attribute))
you can put getattr function in context can call in jinja2 shown below:
{% record in records %} <tr> {% attribute in record.properties() %} <td>{{ getattr(record, attribute) }}</td> {% endfor %} </tr> {% endfor %}
Comments
Post a Comment