LOOPING THROUGH CAROUSEL IN DJANGO PYTHON
When rendering data to the templates through database for carousel, the active class seems to create a problem for many of the beginners. When you use for loop logic to iterate over your slider in the front end, the loop will create three carousels with class set active to each. To avoid this you can use if-else syntax inside the for loop. A simple example would be this one.
<div class="carousel-inner" role="listbox">
{% for j in image_slider %}
<div class="carousel-item {% if forloop.first %} active {% endif %}">
<img src="{{j.slider_img.url}}">
<div class="carousel-caption text-center">
<h1>{{j.main_heading}}</h1>
<h3>{{j.sub_heading}}</h3>
</div>
</div>
{% endfor %}
The above code will set carousel class 'active' for the first loop and then the rest of the class, it won't and your carousel will work perfectly fine. Here's what I have been working on.
My slider working fine. These are fetched directly from the admin dashboard. Logo and slider samples are taken from Internet and I am not creating this one for business or selling purposes, just for fun :). Cheers to Stack Overflow.
Leave LOOPING THROUGH CAROUSEL IN DJANGO PYTHON to:
Read more #programming posts
Best Posts From Leo Umesh
We have not curated any of leoumesh's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Leo Umesh
- The Tattoo of My Newborn Baby Girl Forever Inked on My Skin
- Long Weekend Food Feast With Wife
- String Manipulation in C#: Part 2
- String Manipulation in C#
- Introduction to C# and .NET
- Weekend Escape To Falls
- Evening Barbecue With Favourite Beer 🍺 🍻
- NumPy Broadcasting
- Summer BBQ
- Review of "The Day of The Jackal" Series