我的模板代码:不能在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