我正在使用jija2。我不确定天气我错过了什么,但提到的if语句({%if actors%}...{%endif%}
)似乎不起作用。
actors
是电影名称列表。
{%if actors%}
{%block movies%}
<div class='card-activity col-md-4' id="material-card-info">
<table class="table table-striped table-hover ">
<thead>
<tr>
<th><h5 style="color:#E91E63; font-weight:lighter; font-height:;">Actors</h5></th>
</tr>
</thead>
<tbody>
{%for actor in actors%}
<tr><td>{{actor}}</td></tr>
{%endfor%}
</tbody>
</table>
</div>
{%endblock%}
{%endif%}
这是视图功能:
@app.route('/movie/<b64>')
def profile_movie(b64):
profile = database_search_withid(b64) #returns a tuple eg: ('Avatar', 2012, ['Sam Worthington', 'Zoe Saldana'])
if not profile:
abort(404)
cast= json.loads(profile[2]) #list of actors obtained above is json
actor, actress = filter_feature(cast) #returns actor and actress in separate list
print show
return render_template('movie_profile.html', song_entries=profile, actors=actor, actresses=actress)
即使列表为空,div
内的{%if actors%}
也会显示。我错过了什么?