0
我在view.py以下陣列比較值
chapter = 5
number_of_chapters = 5
selected_chapters = list()
for index in range(1, number_of_chapters+1):
selected_chapters.append(index)
return render(request, 'verses.html', {'chapter': chapter, 'selected_chapters': selected_chapters})
但是當我嘗試在此列表chapter
比較條目它永遠不會返回true
模板
<select name="c" id="chapter" value="{{ chapter }}" onchange="bible_search(true);">
<option value="1">Chapter</option>
{% for c in selected_chapters %}
<option {% if c == chapter %} selected {% endif %} value="{{ c }}">{{ c }}</option>
{% endfor %}
</select>
我想知道如果我需要將字符串轉換爲int或某處?
我的代碼和我給出的示例之間唯一的區別在於章節的數量是從數據庫中檢索的。這是我需要將其轉換爲int的地方。它現在有效。 – Jon 2014-12-07 15:05:47