[Fixed]-Django blogs not looping properly

1👍

<div class="container">
    <h2 class="latest-posts">Latest Posts</h2>
    <hr />

    {% for post in posts.all %}

       {% if forloop.counter0|divisibleby:2 %}

       <div class="row">
       {% endif %}

          <div class="col-12 col-md-6">
              <!-- Card -->
              <article class="card animated fadeInRight">
                  <div class="card-block">
                      <h4 class="card-title"><a href="{% url 'post_detail' post.id %}">{{ post.title }}</a></h4>
                      <h6 class="text-muted">Antoine de Saint-Exupéry</h6>
                      <p class="card-text">{{ post.summary }}</p>
                  </div>
                  <div class="card-block text-center">
                      <div class="btn-group hidden-sm-down hidden-md-down" role="group" aria-label="Card buttons">
                          <a href="#" class="card-link">Read more</a>
                      </div>
                  </div>
                  <img class="card-img-bottom img-responsive" style='width:100%; text-align:center;' src="{{ post.image.url }}" alt="White sand" />
              </article><!-- .end Card -->
           </div>


        </div>

    {% if forloop.counter|divisibleby:2 == False %}
    </div>
    {% endif %}

    {% endfor %}

 // When lenght of posts is even the <div> is not close. Close it!</div>
{% if posts.all|length|divisibleby:2 == False %}

    </div>
    {% endif %}

</div><!-- End container -->

Leave a comment