我正在尝试根据数据库条目的存在性来显示div
:
<table class="info-table">
<tr><td>
<div class="info-table_titlebox">
{% if post.wrk_1_title is defined %}
<div class="info-title_title">
<h2>{{post.wrk_1_title}}</h2>
<h3>Facilitator: {{post.wrk_1_facilitator}}</h3>
<h4>Location: {{post.wrk_1_locate}}</h4>
<h4>Max participants: {{post.wrk_1_max}}</h4>
</div>
<div class="info-title_list">
<ul>
<li>{{post.eventday}} - <b>Week {{post.eventweek}}</b></li>
<li class="info-title_listright">{{post.wrk_1_time}}</li>
</ul>
</div>
<p>{{post.wrk_1_description}}</p>
{% endif %}
</div>
</td>
<td>
<div class="info-table_titlebox">
{% if post.wrk_1_title is defined and post.wrk_2_title is defined %}
<div class="info-title_title">
<h2>{{post.wrk_2_title}}</h2>
<h3>Facilitator: {{post.wrk_2_facilitator}}</h3>
<h4>Location: {{post.wrk_2_locate}}</h4>
<h4>Max participants: {{post.wrk_2_max}}</h4>
</div>
<div class="info-title_list">
<ul>
<li>{{post.eventday}} - <b>Week {{post.eventweek}}</b></li>
<li class="info-title_listright">{{post.wrk_2_time}}</li>
</ul>
</div>
<p>{{post.wrk_2_description}}</p>
{% endif %}
</div>
</td>
这是一个简化版的代码片段 - 模式继续。基本上,如果标题在数据库中,则只显示div1
,如果title1
和title2
都在数据库中,则显示div1
和div2
等等。
目前这种方式有点奇怪,因为它显示了我想要显示的div
,但同时也显示了下一个div
。如果我为div1
的标题设置了标题,它会显示1
和2
,如果我为div1
和2
的标题设置了标题,它会显示1, 2和3
。
我真的很困惑,因为我对Jinja2非常陌生。我不确定是我在HTML中的语法定位错了,还是语法错误,或者你不能检查两个变量……任何帮助都将不胜感激。