我有一个由许多html页面组成的Django项目。
我想在我的html标签中添加一个if else条件,每当时间戳= 0000-00-00 00:00:00时返回“None”,并返回不是的时间。我的代码如下所示,我使用标签来获取日期格式的时间。
<td>{{ table.start_time|date:"Y-m-d G:i:s"}}</td>
答案 0 :(得分:2)
I just used another tag:
<td>{{ table.start_time|date:"Y-m-d G:i:s"|default:"None"}}</td>
Thanks all!!
答案 1 :(得分:1)
You can do this with the ifequal
template tag.
{% with table.start_time|date:"Y-m-d G:i:s" as start_time %}
{% ifequal start_time "0000-00-00 00:00:00" %}None{% else %}{{start_time}}{% endifequal %}
{% endwith %}
答案 2 :(得分:1)
You can try:
{% with table.start_time|date:"Y-m-d G:i:s" as time_stamp %}
{% if time_stamp != "0000-00-00 00:00:00" %}
<td>{{ time_stamp }}</td>
{% endif %}
{% endwith %}
答案 3 :(得分:1)
There is no if-then control explanation in HTML, or whatever other programming capacities. HTML is a markup dialect. Writing computer programs isn't conceivable.
Css will permit you to pick between styles in light of classes and IDs.
You can do this sort of thing with JavaScript, yet you can keep it straightforward with CSS.