[Answer]-Property of model to return iterable to template

1👍

Property values should be accessible using the dot notation:

{{ foo.bar.key }}

Assuming:

@property
def bar(self):
    return {'key':'value'}

your template should render value.

Update as suggested by OP:

To loop on the dictionary key/values at template level use:

{% for k, v in foo.bar.items %}

as in for example:

<table>
    <tr>
        <th>Key</th>
        <th>Value</th>
    </tr>
    {% for k, v in foo.bar.items %}
    <tr>
        <td>{{k}}</td>
        <td>{{v}}</td>
    </tr>
    {%endfor%}
</table>
</ul>

Relevant docs here.

Leave a comment