2012-02-26 3 views
0

Djangoテンプレートでforloopの半分の一部を取得する方法:私は分離する見当がつかないしかし今http://demo.webdeveloperplus.com/drag-drop-panels/ を、私は、Djangoのテンプレート、 を使用してそれを書きました列2の半分?以下は は、私は、別の列に、このような forloopの半分の一部をsperateしたい

は、私が欲しいもの

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

が何であるかを私はループカラム1内のすべての行を次のとおりです。

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

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

おかげ

あなたはあなたのビューに2つのコンテキスト変数作ることができ

答えて

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

ありがとう、私はそれを得た、私はできるそれらをviews.pyに入れてください。 – CSJ

+0

NP、質問を閉じる: – jpic

+0

質問を閉じる必要はありません。彼は自分の答えを投稿するべきです! –

関連する問題