我不确定标题在技术上是否正确(对不起,我是python + django的新手)
我有一个模板页面,该页面显示应用程序正在运行还是已停止取决于其状态。例如:
如果应用正在运行,我想显示:
<div class="lt">
<a class="play" title="App running">
<span class="text_play">Running</span>
</a>
</div>
<div class="rt">
<input type="submit" onclick="stop_app()" value="stop" class="stop">
</div>
Run Code Online (Sandbox Code Playgroud)
如果应用程序未在运行,则显示以下内容:
<div class="lt">
<input type="submit" onclick="star_app()" value="start" class="play">
</div>
<div class="rt">
<a class="stop" title="Application is not running">
<span class="test_stop">Not Running</span>
</a>
</div>
Run Code Online (Sandbox Code Playgroud)
这是一种简化的简化html,但我的观点是如何避免重复自己?
向模板传递了一个应用程序字典,该字典将进行迭代以显示所有应用程序及其状态(正在运行/已停止)。因此,目前我要遍历dict两次,一次是针对“已停止”应用程序,另一次是针对“运行中”应用程序。
希望很清楚
提前致谢
编辑:这是到目前为止我尝试过的:
{% if application.service.status|lower == "enabled" %}
<div>...display running HTML...</div>
{% else %}
<div>...display the non-runing HTML..</div>
{% endif %}
Run Code Online (Sandbox Code Playgroud)
我只想知道我是否在做正确的事(干吗?)