Solution 1 :

         {% for i in product|slice:"1:"%}
                <li>
                    <img src="{{ i.img }}"> 
<!--But in models.p at class  product field img exist !!     -->
                    <div class="sugtd-frnd-meta">
                        <a href="#" title="">{{product.i.product_name}}</a> <!-- fetching from DB -->
                        <span>2 mutual friend</span>
                        <ul class="add-remove-frnd">
                            <li class="add-tofrndlist"><a href="#" title="Add friend"><i class="fa fa-star"></i></a></li>
                            <li class="remove-frnd send-mesg"><a href="#" title="remove friend"><i class="fa fa-comment"></i></a></li>
                        </ul>
                    </div>
            {% endfor %}
                </li>
            </ul>
      </div>
  </div>

Problem :

Here is my settings.py

Static

STATIC_URL = '/static/'
STATIC_DIR = [os.path.join(BASE_DIR, "static")]

Media

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

code for URLs – urls.py

from django.urls import path
from . import views

urlpatterns = [
path("", views.index, name="ShopHome"),

code for Views – views.py

importing

from django.shortcuts import render
from . models import Product
from math import ceil

trying to make sliders to display 4 products(at a time) and iterate through the list of products in the database

def index(request):
        products = Product.objects.all()
        print(products)
        n = len(products)
        nSlides = n//4 + ceil((n/4)-(n//4))
        params = {'no_of_slides':nSlides, 'range': range(1, nSlides), 'product': products}
        return render(request, 'shop/shop.html', params)

code for Template – shop.html

{% load static %}
This is working fine.

    <div class="central-meta">
    <span class="create-post">Robotic Products <a href="#" title="">See All</a>

</span>
        <ul class="suggested-frnd-caro">
          <li>
            <img src="/media/{{product.0.image}}">
               <div class="sugtd-frnd-meta">
                   <a href="#" title="">{{product.0.product_name}}</a>
                    <span>2 mutual friend</span>
                    <ul class="add-remove-frnd">
                       <li class="add-tofrndlist"><a href="#" title="Add friend"><i class="fa fa-star"></i></a></li>
                       <li class="remove-frnd send-mesg"><a href="#" title="remove friend"><i class="fa fa-comment"></i></a></li>
                     </ul>
                </div>
                       </li>

But here I have Problem
Failed to iterate through the list of products which is to be displayed

                {% for i in product|slice:"1:"%}
                    <li>
                        <img src="/media/{{product.i.img}}">
                        <div class="sugtd-frnd-meta">
                            <a href="#" title="">{{product.i.product_name}}</a> <!-- fetching from DB -->
                            <span>2 mutual friend</span>
                            <ul class="add-remove-frnd">
                                <li class="add-tofrndlist"><a href="#" title="Add friend"><i class="fa fa-star"></i></a></li>
                                <li class="remove-frnd send-mesg"><a href="#" title="remove friend"><i class="fa fa-comment"></i></a></li>
                            </ul>
                        </div>
                {% endfor %}
                    </li>
                </ul>
          </div>
      </div>

Comments

Comment posted by Aurélien

Can you share your settings about static contents?

Comment posted by Adarsha B.G

Thanks Aurélien , Just now edited and added the static content

Comment posted by Aurélien

I mean the settings inside the settings.py

Comment posted by Adarsha B.G

Edited my question with settings.py

By