Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (45.3k points)

I have made a loop in index.html and the pics which I added in views.html, whenever I run the code, all the pics appear in rows. I want it to appear in columns. Can anyone provide me the code for it?

Here is my code:

views.py

    def index(request):

    dest1 = Destination()

    dest1.desc = 'Hello, How are you?'

    dest1.img = '01.jpg'

    dest2 = Destination()

    dest2.desc = 'Hello, HOw are you?'

    dest2.img = '02.jpg'

    dests1 = [dest1, dest2]

    return render(request, 'index.html',{'dests1':dests1})

  index.html

    {% static 'images/fulls' as baseUrl %}

    {% static 'images/thumbs' as hiUrl %}

    {% for dest1 in dests1 %}

    <div>

    <a href="{{baseUrl}}/{{dest1.img}}">

        <img src="{{hiUrl}}/{{dest1.img}}" alt="" />

        <h3>{{dest1.desc}}</h3>

    </a>

   </div>

    {%endfor%}

1 Answer

0 votes
by (16.8k points)

Try to add the "row" parameter in your div class, here is what you can add in your code:

<div class="row">

{% for dest1 in dests1 %}

<div class="col-lg-4">

    <a href="{{baseUrl}}/{{dest1.img}}">

        <img src="{{hiUrl}}/{{dest1.img}}" alt="" />

        <h3>{{dest1.desc}}</h3>

    </a>

</div>

{%endfor%}

   </div>

Related questions

Browse Categories

...