如何在django模板中迭代可变长度的列表?
我有一个价值观列表,如:如何在django模板中迭代可变长度的列表?,django,django-templates,Django,Django Templates,我有一个价值观列表,如: list_of_values = ['clients':['add, view'], 'vendors': ['add', 'delete', 'change'], 'companies': ['add', 'view', 'delete', 'change']] 使用django模板标记,我必须制作如下模板: Activities ADD | VIEW | CHANGE | DELETE clients check
list_of_values = ['clients':['add, view'], 'vendors': ['add', 'delete', 'change'], 'companies': ['add', 'view', 'delete', 'change']]
使用django模板标记,我必须制作如下模板:
Activities ADD | VIEW | CHANGE | DELETE
clients checkbox checkbox checkbox checkbox
vendors checkbox checkbox checkbox checkbox
companies checkbox checkbox checkbox checkbox
请告诉我如何才能做到这一点?在我看来,值列表更像是一本字典,假设它是:
<table>
<tr>
<th>Activities</th>
<th>ADD</th>
<th>VIEW</th>
<th>CHANGE</th>
<th>DELETE</th>
</tr>
{% for key in list_of_values %}
<tr>
<td>{{ key }}</td>
<td>
{% if 'add' in list_of_values.key %}
<input type="checkbox" checked/>
{% else %}
<input type="checkbox"/>
{% endif %}
</td>
<td>
{% if 'view' in list_of_values.key %}
<input type="checkbox" checked/>
{% else %}
<input type="checkbox"/>
{% endif %}
</td>
<td>
{% if 'change' in list_of_values.key %}
<input type="checkbox" checked/>
{% else %}
<input type="checkbox"/>
{% endif %}
</td>
<td>
{% if 'delete' in list_of_values.key %}
<input type="checkbox" checked/>
{% else %}
<input type="checkbox"/>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
活动
添加
看法
改变
删除
{u值%u列表中的键为%u}
{{key}}
{%if'add'在\u值列表中。\u.key%}
{%else%}
{%endif%}
{%if'view'在\u值的列表\u.key%}
{%else%}
{%endif%}
{%if'change'在\u值列表中的\u.key%}
{%else%}
{%endif%}
{%if'delete'在\u值列表中的\u.key%}
{%else%}
{%endif%}
{%endfor%}