我的模板代碼:不能在Django模板比較varriables
<select name="channelChoice" id="channelChoice" class="choiceBox">
<option value="0">Chose your channel</option>
{% if channels %}
{% for ch in channels %}
{% if ch.id == default_channel_id %}
<option class="channel-choice" value="{{ ch.id }}" selected="selected" >{{ ch.title }}</option>
{% else %}
<option class="channel-choice" value="{{ ch.id }}" >{{ ch.title }}</option>
{% endif %}
{% endfor %}
{% endif %}
</select>
我的Python代碼:
def index(request):
channels = models.Channel.objects.filter(activated=True).order_by('title')
default_channel_id = request.GET.get('channel_id', False)
if not default_channel_id:
default_channel_id = 1
return render(request, 'epgadmin/index.html', {'channels': channels, 'default_channle_id': default_channel_id})
我通過default_channel_id與值是1,和渠道的清單包含的頻道使用完全相同的ID是1.但是如果從句沒有達到!誰能幫我?
正確default_channel_id的拼寫在這一行:「返回渲染(請求'epgadmin/index.html',{'channels':channels,'default_channle_id':default_channel_id})「。 – Ymartin 2014-12-04 05:21:05