Tips on utilizing a for loop in Django to display blog posts side by side

My title may not be clear, but let me explain. I have a list of blog posts that I want to display next to each other using a for loop. However, they are currently displaying in a vertical layout which is not what I want. You can see how it looks currently in this image: this is how it is in the picture, and this is how I would like them to look like in a picture: {this is how I want them to look like in a picture}.

blog.html

<section class="ftco-section bg-light" id="blog-section">
      <div class="container">
        <div class="row justify-content-center mb-5 pb-5">
          <div class="col-md-10 heading-section text-center ftco-animate">
            <h2 class="mb-4">Get Every Single Update Here</h2>
            <p>Far far away, behind the word mountains, far from the countries Vokalia and Consonantia</p>
          </div>
        </div>
        <div class="row justify-content-center mb-5 pb-5">
          <div class="col-md-4 ftco-animate">
           {% for blog in blog_post %}
            <div class="blog-entry ">  
              <a href="blog-single.html" class="block-20" style="background-image: url({{ blog.thumbnail.url }})">
              </a>
              <div class="text d-block">
                <div class="meta mb-3">
                  <div><a href="#">{{ blog.timestamp|timesince }} ago</a></div>
                  <div><a href="#">{{ blog.user }}</a></div>
                  <div><a href="#" class="meta-chat"><span class="icon-eye"></span>{{ blog.view_count }}</a></div>
                </div>
                <h3 class="heading"><a href="#">{{ blog.title }}</a></h3>
                <p>Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.</p>
                <p><a href="blog-single.html" class="btn btn-primary py-2 px-3">Read more</a></p>
            
              </div>
              {% endfor %}
            </div>
            </div>
        </div>
      </div>
    </section>

Answer №1

  <div class="row d-flex">
         {% for blog in blog_post %}
          <div class="col-md-4 ftco-animate">
            <div class="blog-entry "> 
              <a href="{% url 'blog-detail' blog.id %}" class="block-20" style="background-image: url({{ blog.image.url }})"></a>
              <div class="text d-block">
                <div class="meta mb-3">
                  <div>{{ blog.timestamp|timesince }} ago</div>
                  <div><a href="{% url 'user-blog' blog.doctor.user.username %}">Written By {{ blog.doctor.user.username }}</a></div>
                </div>
                <h3 class="heading"><a href="{% url 'blog-detail' blog.id %}">{{ blog.title }}</a></h3>
                <p>{{ blog.summary }} </p>
                <p><a href="{% url 'blog-detail' blog.id %}" class="btn btn-primary py-2 px-3">Read more</a></p>
              </div>
            </div>
            </div>
          
          {% endfor %}
        </div> 
      </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Jquery's mouseclick event selects an excessive number of elements

Is there a way to retrieve the ID of an element when it is clicked, only if it has one? I currently have this code set up to alert me with the element's ID: $("[id]").click(function(event) { event.preventDefault(); var id_name = $(this).attr ...

Utilize flexbox to create a list that is displayed in a column-reverse layout

I am facing a challenge in displaying the latest chat person in the 1st position (active) using Firebase. Unfortunately, Firebase does not have a date field which makes it difficult to achieve this. I have attempted converting the date into milliseconds an ...

Repeated tweets detected within real-time Twitter stream

I've been working on developing a live update Twitter feature, but I've noticed that it sometimes duplicates tweets and behaves erratically. Did I make a mistake somewhere in my code? http://jsfiddle.net/JmZCE/1/ Thank you in advance (note: I p ...

I'm noticing that the top border for my span is smaller than the bottom one. What could

I am struggling to create an arrangement of three triangles in a line, with the first and third pointing up and the middle one pointing down. The upper triangle seems to be too small - any ideas on how to adjust this? Is there another way to achieve this ...

Delete the item if the link uses Javascript: void(0)

<a class="slicknav_item" href="home">Home<span></span></a> <a class="slicknav_item" href="about">About<span></span></a> <a class="slicknav_item" href="javascript: void(0)">Services<span></span& ...

Jquery ajax is failing to achieve success, but it is important not to trigger an error

My jQuery ajax request seems to be stuck in limbo - it's not throwing an error, but it also never reaches the success function. This is how my code looks: function delete() { $("input[name='delete[]']:checked").each(function() { ...

Boxes not occupying entire vertical space

My structure is unique, like a 9-box with div elements: <div class="NBWrapper"> <div class="NBTopRow"> <div class="NBLeft" /> <div class="NBRight" /> <div class="NBMiddle" /> </div> & ...

Discovering the best locations for locating CSS color codes

I came across this question which led me to search for the color codes of green, red and yellow in decimal format for the rgba() function. According to this website, I found that green is represented by #008000, equivalent to rgb(0, 128, 0). However, I a ...

Determine the div's width inside the viewport

I am trying to determine the width of a div within the viewport. When using .css(width) on my div, it calculates the overall width instead. Here is the code I am currently using: var $Windowwidth = $(window).width(); var $lefty = $("#gallerytop"); var $G ...

Step-by-step guide to correctly set up django-import-export

I have been attempting to import excel sheets into my Django database by installing django-import-export. Despite following the instructions provided in this tutorial, I encountered an issue when trying to run the server – an error stating that there is ...

The toggle in the dialog box refuses to submit the information

I am facing an issue with a dialog box that I am displaying using the jQuery .dialog() function. The dialog box contains a button that I want to use to post back to another page, but for some reason, it is not working as expected. I have tried setting the ...

Guide to transferring a series of numerical data from a website to a server through an Ajax request

I'm facing an issue with my ajax implementation. I am trying to send an array of integers that are selected using checkboxes. The array is populated correctly, but when it is sent to the controller method, it becomes null. Here is the Ajax code snipp ...

Ways to add a substantial quantity of HTML to the DOM without relying on AJAX or excessive strings

Currently, I am looking to update a div with a large amount of HTML content when a button on my webpage is clicked. The approach I am currently using involves the .html() method in JQuery, passing in this extensive string: '<div class="container-f ...

The form cannot be submitted within the ajax success function

I have a contact form with Google reCAPTCHA. I need to validate the captcha before submitting the form, but even though my jquery code validates it correctly, I am unable to submit the form when the result is true. jQuery('#citygreen-contact-us-submi ...

Iterate through every row in the table in order to carry out a mathematical operation

I have created a jQuery function to add a table dynamically: $(document).on('click', '.add', function(){ var html = ''; html += '<tbody><tr>'; html += '<td><select name="product_name[]" cla ...

Utilizing CSS for styling a specific class in a Joomla Module

Recently, I was working on a Joomla Module and came across an interesting issue. When inspecting the CSS using Firebug, I noticed that there were multiple nested divs within the module, each with its own class. One example of this structure looked like: & ...

Python and Django error: Date lookup not supported for DateField or joining on the field is not allowed

I utilize a straightforward approach. Entries in a time sheet application are where employees input their hours. class Entry(m.Model): """ Represents an entry in a time_sheet. An entry can be for work, sick leave, or vacation. """ # type choices ...

Fundamental CSS - the technique of layering a DIV with a semi-transparent DIV on top

Having trouble getting this to display correctly in my Chrome browser. I have a wrapper containing all the HTML elements, and I want to create a DIV (let's call it div-1) that includes an image with an overlay div positioned to the left, as shown in t ...

Is it dependable to use jQuery to trigger ajax upon click in order to reliably work sequentially on the database?

Imagine there are 4 radio buttons on a webpage, and when any of them is clicked, it triggers an ajax call to save the button's value in a database. If the user clicks the first radio button (with a value of 1), an ajax call will be made to save this ...

Converting JSON Date to Bootstrap's datepicker control

Here is a snippet featuring a bootstrap datepicker control. I have a JSON array and I am displaying its parsed result. How can I fetch it to an input textbox while maintaining compatibility with the datepicker? This means that when you click on the field, ...