2012-02-26 72 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