【发布时间】:2020-10-11 00:01:25
【问题描述】:
我正在尝试在 jinja 中使用两个命名空间变量。一个人将决定是否会显示一些 html,而另一个变量用于更改第一个。但是,只有我的 ns.show 变量有效,我很困惑
<html>
<body>
<h2>Release Notes</h2>
{% set ns = namespace(show="true")%}
{% set ns2 = namespace(current="text")%}
{% for item in items %}
<!-- This needs to only show up when scrumName is new -->
<!-- check if the scrum name new. if so use this code -->
{% set ns = namespace(show="false")%}
<p> 1 ; current is {{ns2.current}} | scrumName is {{item.scrumName}}</p>
{% if ns2.current != item.scrumName %}
{% set ns = namespace(show="true")%}
{% endif %}
{% set ns2 = namespace(current = item.scrumName)%}
<p> 2; current is {{ns2.current}} | scrumName is {{item.scrumName}}</p>
<p> show is {{ns.show}} 2 </p>
{% if ns.show == "true" %}
<h3>{{ item.scrumName }}</h3>
<table style="width:100%">
<tr>
<th>Epic Name</th>
<th>Story Name</th>
<th>Release Type</th>
<th>Release Date</th>
<th>Epic % Completion</th>
</tr>
{% endif %}
<!-- ends here -->
<!-- This show up everytime -->
<tr>
<td>{{ item.epicName }}</td>
<td>{{ item.storyName }}</td>
<td>{{ item.type }}</td>
<td>{{ item.date }}</td>
<td>{{ item.completion }}</td>
</tr>
<!-- ends here -->
{% endfor %}
</table>
</body>
</html>
【问题讨论】:
-
对我来说,您应该在发送到 jinja 之前用 Python 代码重新组织数据。然后在 jinja 中你不需要命名空间。
标签: python html templates jinja2