【发布时间】:2014-10-15 15:53:34
【问题描述】:
http://localhost.com:8000/dashboard/track_info/13/这个页面有下拉菜单,用户可以选择国家。如果用户返回同一页面..这里我想默认显示选定的国家。
我尝试了以下但遗憾的是没有工作......
<option value=""></option>
{% for country in country_list %}
<option value="{{ country.id }}" {% if country.id == get.territory_code_id %} selected="selected" {% endif %}>{{ country.country_name | safe }}</option>
{% endfor %}
get.territory_code_id 来自会话,值为 2
你能在这里发现错误吗? ?
【问题讨论】:
-
您确定该值为 int 2 而不是字符串“2”
-
@StuartLeigh 我不知道.. 但流程是...|
{{ country.id }}是2然后request.POST['territory_code']将只选择2.. 最后我会将这个值保存到会话中request.session[event_id]['territory_code_id'] -
我想你会发现
request.POST['territory_code']是一个字符串,尝试将int(request.POST['territory_code'])设置为会话,看看是否能解决你的问题。 -
@StuartLeigh Ya ... 工作正常... make ans..
标签: python django django-templates