0
我已經在我的模板如下:Django的:模板if語句執行,即使假
<li{% if selected == "al" %} id="selected" {% endif %}><a href="/posting/alerts">Alerts{% if alertnum != 0 %}<span style="color:red">({{alertnum}})</span>{% endif %}</a></li>
的問題是似乎alertnum != 0
。我有以下看法:
def posting_draft(request):
user = request.user
user_drafts = Draft.objects.filter(user = user)
drafts = dict()
for d in user_drafts:
drafts[d.title] = d.id
alertnum = get_alertnum(user) # Returns 0. I have used print statements to verify this
return render_to_response('posting_draft.html', {'STATIC_URL':STATIC_URL, 'draft_l' : drafts, 'selected':"dr", alertnum: alertnum})
什麼在瀏覽器中顯示,當我打開這個,是Alert()
空紅色括號。括號不應該存在,因爲在所有alertnum = 0