开发者

Django template-printing variables

开发者 https://www.devze.com 2022-12-18 15:08 出处:网络
All, In Template condition check,whats wrong with the following code, selected_id and selected_sub are equal to 5 but still ifequal loop is not working..

All,

In Template condition check,whats wrong with the following code,

selected_id and selected_sub are equal to 5 but still ifequal loop is not working..

<tr><td><p>Subjects:</td>
<td>
<select id="subjects" name="subje开发者_如何学Ccts" multiple="multiple">
{% for subject in subjects %}
<option value="{{subject.id}}" {% for selected_id in selected_sub %}{% ifequal subject.id selected_id %} {{ selected }} {% endifequal %} {% endfor %} >{{subject.subject}}</option>
{% endfor %} 
</select>
</p></td></tr>

Thanks..........


Ok, sorry. What is the output you get?

selected should have the value 'selected="selected"'.

Change to {% with selected as 'selected="selected"' %} and try again.


If, as you say, selected_id and selected_sub are equal to 5 then

for selected_id in selected_sub

will not work, since 5 is not iterable.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号