Issue
I am trying to access a variable of a object in jinja2 using this code:
{% for row in rows.items %}
<tr>
{% for column in model_settings['table_columns'] %}
<td>
<p>{{ row.column }}</p>
</td>
{% endfor %}
</tr>
{% endfor %}
what I want is if column was username I would want it to give me
row.username
. sorry for the bad explanation.
Solution
Jinja2 has the builtin attr
filter to access an attribute of an object. The name of the attribute can be a static string, or in your case: a string stored in a variable:
{% for row in rows.items %}
<tr>
{% for column in model_settings['table_columns'] %}
<td>
<p>{{ row|attr(column) }}</p>
</td>
{% endfor %}
</tr>
{% endfor %}
Answered By - Dauros
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.