第二个循环没有在django模板中执行

时间:2014-07-03 12:30:43

标签: python django django-templates

我很奇怪。

这是我的模板

<table class="table table-striped table-condensed tablesorter" id="myTable">
             <thead>
                        <tr>
                            <th>Store</th>
                            <th>Image</th>
                            <th>Price(USD)</th>
                            <th>Manufacturer</th>
                            <th>Model</th>
                            <th>Shipping</th>
                            <th>Replacement</th>
                            <th>Details</th>
                        </tr>
                    </thead>
                    <tbody>
                   {% for x in result_amazon|slice:"1" %}     
                    {% if forloop.first  %}                         <tr>
                             <td>
                                 <a href="" target="_blank">
                                    <img height="85" width="110" src={% static "images/Amazon-Logo.jpg" %} alt="">
                                 </a>
                             </td>
                             <td><img   src={{x.medium_image_url}} alt=""></td>
                             <td><strong><span class="WebRupee"></span> 
                            {% for y in x.list_price %}
                                             {% if y.price != 'None'%}   
                                                {{y}}
                                            {% endif %}
                             {% endfor %}</strong>
                          </td>
                             <td>{{x.manufacturer}}</td>
                             <td>{{x.model}}</td>
                             <td>Rs. 99</td>
                             <td>Out of Stock</td>
                             <td>
                                 <a href="{{x.detail_page_url}}" class="btn btn-mini btn-primary trackinfo" rel="7#@#17205" title="Visit Store" target="_blank">
                                    Visit Store
                                  </a>
                          </td>
                             </tr>
                    {% endif %}    
                  {% endfor %}



             {% for x in result_bestbuy.products %}                                                                                                                                 
                {% if  forloop.first %}
                        <tr>
                            <td>
                                <a href="">
                                   <img height="85" width="110"  src={% static "images/bestbuy.gif" %} alt="">
                                </a>
                            </td>
                            <td><img style="height: 168px;" src={{x.image}} alt=""></td>
                            <td><strong><span class="WebRupee"></span>{{x.regularPrice}}</strong></td>
                            <td>{{x.manufacturer}}</td>
                            <td>{{x.modelNumber}}</td>
                            <td>{% if x.freeShipping %}Free Shipping  {% else %}{{x.shippingCost }}{% endif %}</td>
                            <td>14 Days</td>
                            <td>
                                <a href="{{x.url}}" class="btn btn-mini btn-primary trackinfo" rel="27#@#17205" title="Visit Store" target="_blank">
                                   Visit Store
                                </a>
                           </td>
                        </tr>
                 {% endif %}
                 {% endfor %}
              {% for x in result_amazon %} 
                {% if not forloop.first %}                 
                        <tr>
                             <td>
                                 <a href=""> </a>
                                   <img height="85" width="110" src={% static "images/Amazon-Logo.jpg" %} alt="">
                                 </a>
                             </td>
                             <td><img   src={{x.medium_image_url}} alt=""></td>

                             <td><strong><span class="WebRupee"></span> 
                                    {% for y in x.list_price %}
                                                     {% if y.price != 'None'%}   
                                                        {{y}}
                                                    {% endif %}
                                    {% endfor %}
                                 </strong>
                          </td>
                             <td>{{x.manufacturer}}</td>
                             <td>{{x.model}}</td>
                             <td>Rs. 99</td>
                             <td>Out of Stock</td>
                             <td>
                                 <a href="{{x.detail_page_url}}" class="btn btn-mini btn-primary trackinfo" rel="7#@#17205" title="Visit Store" target="_blank">
                                    Visit Store
                                 </a>
                          </td>
                             </tr>
                        {% endif %}
                      {% endfor %}

                   {% for x in result_bestbuy.products %} 

                       {% if not  forloop.first %}
                        <tr>
                            <td>
                                <a href=""> </a>
                            </td>
                            <td><img style="height: 168px;" src={{x.image}} alt=""></td>
                            <td><strong><span class="WebRupee"></span>{{x.regularPrice}}</strong></td>
                            <td>{{x.manufacturer}}</td>
                            <td>{{x.modelNumber}}</td>
                            <td>{% if x.freeShipping %}Free Shipping  {% else %}{{x.shippingCost }}{% endif %}</td>
                            <td>14 Days</td>
                            <td>
                                <a href="{{x.url}}" class="btn btn-mini btn-primary trackinfo" rel="27#@#17205" title="Visit Store" target="_blank">
                                   Visit Store 
                                </a>
                           </td>
                </tr>
                         {% endif %}
                {% endfor %}
                      </tbody>
            </table>

我试图限制第一个循环最初只执行一次然后休息全部必须执行因此我已应用forloop.first条件。

我的简单问题是"Why the third loop(result_amazon) is not printing any data"(result_amazon中有很多数据)。

请帮助我解决我在这里做错的事。

1 个答案:

答案 0 :(得分:0)

检查浏览器的控制台,查找html代码中的任何错误。