2013-04-10 53 views
0

您好我有一個購物車網站在這搭載的Django 我用下面的代碼排除第一個值從的foreach Django的

{% for image in images %} 
    <li> 
     <a rel="zoom-id:zoom;" rev="{{ MEDIA_URL }}{% thumbnail image.file 510 700 %}" class="MagicThumb-swap" href="{{ MEDIA_URL}}{% thumbnail image.file 2500 3500 %}"> 
      <img alt="{{ image.description }}" src="{{ MEDIA_URL }}{% thumbnail image.file 75 100 %}"> 
     </a> 
    </li> 
{% endfor %} 

具有multile圖像了產品的縮略圖

image1.jpg 
image2.jpg 
image3.jpg 

我需要顯示來自在foreach第一圖像或數值。

回答

0

據我瞭解,你想從圖像只顯示1圖像。

所以,你可以使用slice過濾器,以削減你的名單分成1項和使用,像

{% for image in images|slice:"1" %} 

    {# your code #} 

{% endfor %} 

或者你可以使用forloop.first,並有代碼,例如

{% for image in images %} 
    {% if forloop.first %} 

     {# your code #} 

    {% endif %} 
{% endfor %} 

更新:

先排除並顯示剩餘

{% for image in images %} 
    {% if forloop.first %} {# Do nothing #} 
    {% else %} 

     {# your code #} 

    {% endif %} 
{% endfor %} 
+0

我可以ecclude第一個和顯示remaimination – user2106353 2013-04-10 10:03:58

+0

我的意思是我可以排除一個特定的數字,並顯示所有其他 – user2106353 2013-04-10 10:06:06

+0

@ user2106353,檢查更新的答案,排除第一 – Rohan 2013-04-10 10:06:29

相關問題