Click here to Skip to main content
15,743,426 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I'm making a website using Django and Bootstrap but I'm unable to find out the error.

This is

from django.db import models

# Create your models here.

class Product(models.Model):
    product_id = models.AutoField
    product_name = models.CharField(max_length=50)
    category = models.CharField(max_length=50,default="")
    subcategory = models.CharField(max_length=50,default="")
    price = models.IntegerField(default=0)
    desc = models.CharField(max_length=300)
    pub_date= models.DateField()
    image = models.ImageField(upload_to="shop/images",default="")

    def __str__(self):
        return self.product_name

This is
from django.shortcuts import render
from .models import Product
from math import ceil
# Create your views here.
from django.http import HttpResponse
def index(request):
    # products= Product.objects.all()
    # n= len(products)
    # nSlides= n//6 + ceil((n/6) - (n//6))
    # params={'no_of_slides':nSlides, 'range':range(1,nSlides), 'product': products}
    allProds = []
    catprods = Product.objects.values('category','id')
    cats = {item['category'] for item in catprods}
    for cat in cats:
        prod = Product.objects.filter(category = cat)
        n = len(prod)
        nSlides = n // 6 + ceil((n / 6) - (n // 6))
        allProds.append([prod,range(1 , nSlides), nSlides])
        params = {'allProds': allProds}
    return render(request,"shop/index.html", params)
def about(request):
    return render(request , 'shop/about.html')
def contact(request):
    return HttpResponse("We are at contact")
def tracker(request):
    return HttpResponse("We are at tracker")
def search(request):
    return HttpResponse("We are at search")
def productView(request):
    return HttpResponse("We are at product view")
def checkout(request):
    return HttpResponse("We are at checkout")

This is
from django.contrib import admin
from django.urls import path
from . import views

urlpatterns = [
    path("",views.index, name ="ShopHome"),
    path("about/",views.about,name="About us"),

This is index.html
{% extends 'shop/basic.html' %}
{% block title%} index.html {% endblock %}
{% block css %}
    position: relative;
    width: 100%;
    overflow: hidden;
    padding-top: 20px;
    padding-left: 10px;
    padding-right: 10px;
{% endblock %}
{% load static %}
{% block body %}
  <!--navbar will come here-->
  <!--carousel starts here-->
  {% load static %}

{% for product, range, nSlides in allProds %}
  <div id="carouselExampleIndicators{{forloop.counter}}" class="carousel slide" data-bs-ride="carousel">
    <!--slides buttons starts from here-->
  <div class="carousel-indicators">
    <button type="button" data-bs-target="#carouselExampleIndicators{{forloop.counter}}" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
     {% for i in range %}
    <button type="button" data-bs-target="#carouselExampleIndicators{{forloop.parentloop.counter}}" data-bs-slide-to="1" aria-label="Slide 2"> </button>
{% endfor %}
     <!--slides buttons ends here-->
    <!--slides inner starts from here-->
      <div class="container" style="padding-top: 20px;">
  <div class="carousel-inner">
    <div class="carousel-item active">
      <!--card group starts here-->
      <div class="card-group">
           {% for i in product %}
        <!--card starts from here-->
  <div class="card" style="min-height:500px;  max-width:253.5px;">
    <!--card image-->
    <img src="/media/{{i.image}}" class="card-img-top" alt="..." style="min-height:250px; max-height:250px;"/>
    <div class="card-body">
      <h5 class="card-title">{{i.product_name}}</h5>
      <p class="card-text">{{i.desc}}</p>
    <div class="card-footer">
     <button id="pr{{}}" class="btn btn-primary btn-sm cart">Add to cart</button>
 {% if forloop.counter|divisibleby:6 and forloop.counter > 0 and not forloop.last %}
      <!--card ends here-->
      <div class="carousel-item">

       {% endif %}

       {% endfor %}

    <!--slides inner ends here-->
  <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators{{forloop.counter}}" data-bs-slide="prev">
  <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators{{forloop.counter}}" data-bs-slide="next">

  <!--carousel ends here-->
{% endfor %}

{% endblock %}

{% block js %}
<script src=""></script>
<script src="js/bootstrap.js"></script>
if(localStorage.getItem('cart')== null){
var cart = {};
cart = JSON.parse(localStorage.getItem('cart'))
document.getElementById('cart').innerHTML = Object.keys(cart).length;
var idstr =;
if (cart[idstr] !=undefined){
cart[idstr] = cart[idstr] + 1;
cart[idstr] = 1;
localStorage.setItem('cart', JSON.stringify(cart));
document.getElementById('cart').innerHTML = Object.keys(cart).length;

{% endblock js%}

What I have tried:

This is basic.html
<!doctype html>
<html lang="en">
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="" rel="stylesheet"
          integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

    <title>{% block title%} {% endblock %}</title>
  <body style="background-color:grey;">
<!--  adding navbar-->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Stockpile</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        <li class="nav-item">
          <a class="nav-link" href="#">About</a>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
          <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
            <li><a class="dropdown-item" href="#">Men</a></li>
            <li><a class="dropdown-item" href="#">Women</a></li>
            <li><a class="dropdown-item" href="#">Girls</a></li>
            <li><a class="dropdown-item" href="#">Boys</a></li>
            <li><a class="dropdown-item" href="#">Kids</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="#">Accessories</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="#">Home Shopping</a></li>
        <li class="nav-item">
          <a class="nav-link " href="#" tabindex="-1" aria-disabled="true">Contact Us</a>
         <li class="nav-item">
        <a class="nav-link" href="#">Cart(<span id="cart">0</span>)</a>
      <form class="d-flex">
        <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
        <button class="btn btn-outline-success" type="submit">Search</button>

{% block body %} {% endblock %}
    <script src="" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
{% block js %} {% endblock js %}
Richard MacCutchan 21-Jul-21 6:40am    
Saying, "not working", is the single most useless comment we see on these forums. And just dumping all your code and expecting us to a) work out what the problem is and where it occurs, and b) provide a full solution, is rather rude.

So, please use the Improve question link below your question, and add complete details of the problem and exactly where it occurs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900