2012-02-26 28 views
0

我想sperate for循環的半部分在另一列, 這樣的:http://demo.webdeveloperplus.com/drag-drop-panels/ 現在,我寫的使用Django模板, 但是我不知道分離一半放入第二欄?如何獲取for循環的在Django模板半部分

下面是我環路COLUMN1所有線路

<div class="column" id="column1"> 
<ul> 
{% for line in lines %} 
     <li>{{ line.node }}</li> 
{% endfor %} 
</ul> 
</div> 

我想要的是:

<div class="column" id="column1"> 
half nodes 
</div> 

<div class="column" id="column2"> 
the another half nodes 
</div> 

感謝

回答

1

你可以讓你的視圖中的兩個方面變量:

offset = len(lines)/2 

if offset % 2 != 0: 
    # ensure that the second col does not contain more than the first one 
    offset += 1 

lines_col0 = lines[:offset] 
lines_col1 = lines[offset:] 
+0

謝謝,我明白了,我可以fil在views.py中刪除它們。 – CSJ 2012-02-26 14:54:32

+0

NP,請關閉該問題:) – jpic 2012-02-26 15:01:24

+0

無需關閉該問題。他應該發表他自己的答案! – 2012-03-23 13:18:25