user
user

Reputation: 317

feed page - django/HTML

I am creating a social network website using Django, HTML. I have a blog list page which lists all the posts from users. How can I list the posts in separate tiles or containers on the blog list page like fb. Currently it displays all the posts in a single container. But I want them to separate. Thanks.

blog_list.html

  <section>

    <br>
  <div class="container" id ="main-cont">
    <div class="row">
     <div class="panel panel-default post">
      <div class ="panel-body">
       <div class ="row">
        <div class = "col-sm-1">
          <a class ="post-avatar thumbnail" href = "#"><img src ="{% static 'img/group.png' %}"></a>
        <!--  <hr>Created By: {{ post.author }}-->
        <div>
          {% for post in post_list %}
              <div class="post">

                  <h2><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}<br></h2>

                    <br>
                    <br>



          {% endfor %}
      </div>
      {% endblock %}

Upvotes: 0

Views: 74

Answers (1)

Shameer Kashif
Shameer Kashif

Reputation: 444

I am not sure why you just don't iterate again over the post_list loop and span a new container. However, this very same thing could be done with a couple other ways. Not sure which suits the best. The simplest is to do it using the {% if %} directive to get the current loop in progress:

{% for post in post_list %}
    {% if forloop.counter > 5 %}  # Logic for new container
        <div>New Containers</div>
    {% else %}
        <div>First Five Containers</div>
    {% endfor %}
{% endfor %}

Upvotes: 1

Related Questions