For every single HTML file like,

  • index.html
  • about.html

do you think you’ve to re-write again?


let’s create a sample.html

Untitled 5.png

it’ll be our base!


let’s head over to views.py to populate our about page!

def about(request):
    return render(request, 'shop/about.html')

now, again it’s basic.html

<!doctype html>
<html lang="en">
 
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
 
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
        integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
 
    <title>{% block title %}{% endblock %}</title>
</head>
 
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <a class="navbar-brand" href="#">My Awesome Cart</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="\#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
 
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item active">
                    <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Link</a>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
                        data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        Dropdown
                    </a>
                    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                        <a class="dropdown-item" href="#">Action</a>
                        <a class="dropdown-item" href="#">Another action</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="#">Something else here</a>
                    </div>
                </li>
                <li class="nav-item">
                    <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
                </li>
            </ul>
            <form class="form-inline my-2 my-lg-0">
                <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
                <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
            </form>
        </div>
    </nav>
 
    {% block body %}{% endblock %}
 
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"
        integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"
        crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"
        integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"
        crossorigin="anonymous"></script>
</body>
 
</html>

here I used bootstap no big deal! just go to it’s site and grab whatever!

now, notice,

<title>{% block title %}{% endblock %}</title>

it’s like a placeholder for us!


now let’s make our about.html with the help of this basic.html

{% extends 'shop/basic.html' %}
{% block title %}About page{% endblock %}
{% block body %}This is my body{% endblock %}

That’s it! Enjoy!


BTW, stolen a index.html for our shop’s homepage from code with harry

{% extends 'shop/basic.html' %}
 
{% block body %}
{% load static %}
 
<style>
  .col-md-3 {
    display: inline-block;
    margin-left: -4px;
  }
 
  .carousel-indicators .active {
    background-color: blue;
  }
 
  .col-md-3 img {
    width: 100%;
    height: auto;
  }
 
  body .carousel-indicator li {
    background-color: blue;
  }
 
  body .carousel-indicators {
    bottom: 0;
  }
 
  body .carousel-control-prev-icon,
  body .carousel-control-next-icon {
    background-color: blue;
  }
 
  body .no-padding {
    padding-left: 0;
    padding-right: 0;
  }
</style>
 
<div class="container">
  <div id="demo" class="carousel slide my-3" data-ride="carousel">
    <ul class="carousel-indicators">
      <li data-target="\#demo" data-slide-to="0" class="active"></li>
      <li data-target="\#demo" data-slide-to="1"></li>
      <li data-target="\#demo" data-slide-to="2"></li>
    </ul>
 
    <!--Slideshow starts here -->
    <div class="container carousel-inner no-padding">
 
      <div class="carousel-item active">
        <div class="col-xs-3 col-sm-3 col-md-3">
          <div class="card" style="width: 18rem;">
            <img src='{% static "shop/test.jpg" %}' class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Card title</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the
                card's content.</p>
              <a href="#" class="btn btn-primary">Go somewhere</a>
            </div>
          </div>
        </div>
 
        <div class="col-xs-3 col-sm-3 col-md-3">
          <div class="card" style="width: 18rem;">
            <img src='{% static "shop/test.jpg" %}' class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Card title</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the
                card's content.</p>
              <a href="#" class="btn btn-primary">Go somewhere</a>
            </div>
          </div>
        </div>
 
        <div class="col-xs-3 col-sm-3 col-md-3">
          <div class="card" style="width: 18rem;">
            <img src='{% static "shop/test.jpg" %}' class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Card title</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the
                card's content.</p>
              <a href="#" class="btn btn-primary">Go somewhere</a>
            </div>
          </div>
        </div>
 
        <div class="col-xs-3 col-sm-3 col-md-3">
          <div class="card" style="width: 18rem;">
            <img src='{% static "shop/test.jpg" %}' class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Card title</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the
                card's content.</p>
              <a href="#" class="btn btn-primary">Go somewhere</a>
            </div>
          </div>
        </div>
      </div>
 
 
 
      <div class="carousel-item">
        <div class="col-xs-3 col-sm-3 col-md-3">
          <div class="card" style="width: 18rem;">
            <img src='{% static "shop/test.jpg" %}' class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Card title</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the
                card's content.</p>
              <a href="#" class="btn btn-primary">Go somewhere</a>
            </div>
          </div>
        </div>
 
        <div class="col-xs-3 col-sm-3 col-md-3">
          <div class="card" style="width: 18rem;">
            <img src='{% static "shop/test.jpg" %}' class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Card title</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the
                card's content.</p>
              <a href="#" class="btn btn-primary">Go somewhere</a>
            </div>
          </div>
        </div>
 
        <div class="col-xs-3 col-sm-3 col-md-3">
          <div class="card" style="width: 18rem;">
            <img src='{% static "shop/test.jpg" %}' class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Card title</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the
                card's content.</p>
              <a href="#" class="btn btn-primary">Go somewhere</a>
            </div>
          </div>
        </div>
 
        <div class="col-xs-3 col-sm-3 col-md-3">
          <div class="card" style="width: 18rem;">
            <img src='{% static "shop/test.jpg" %}' class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Card title</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the
                card's content.</p>
              <a href="#" class="btn btn-primary">Go somewhere</a>
            </div>
          </div>
        </div>
      </div>
 
      <div class="carousel-item">
        <div class="col-xs-3 col-sm-3 col-md-3">
          <div class="card" style="width: 18rem;">
            <img src='{% static "shop/test.jpg" %}' class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Card title</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the
                card's content.</p>
              <a href="#" class="btn btn-primary">Go somewhere</a>
            </div>
          </div>
        </div>
 
        <div class="col-xs-3 col-sm-3 col-md-3">
          <div class="card" style="width: 18rem;">
            <img src='{% static "shop/test.jpg" %}' class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Card title</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the
                card's content.</p>
              <a href="#" class="btn btn-primary">Go somewhere</a>
            </div>
          </div>
        </div>
 
        <div class="col-xs-3 col-sm-3 col-md-3">
          <div class="card" style="width: 18rem;">
            <img src='{% static "shop/test.jpg" %}' class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Card title</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the
                card's content.</p>
              <a href="#" class="btn btn-primary">Go somewhere</a>
            </div>
          </div>
        </div>
 
        <div class="col-xs-3 col-sm-3 col-md-3">
          <div class="card" style="width: 18rem;">
            <img src='{% static "shop/test.jpg" %}' class="card-img-top" alt="...">
            <div class="card-body">
              <h5 class="card-title">Card title</h5>
              <p class="card-text">Some quick example text to build on the card title and make up the bulk of the
                card's content.</p>
              <a href="#" class="btn btn-primary">Go somewhere</a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
 
  <!-- left and right controls for the slide -->
  <a class="carousel-control-prev" href="\#demo" data-slide="prev">
    <span class="carousel-control-prev-icon"></span>
  </a>
  <a class="carousel-control-next" href="\#demo" data-slide="next">
    <span class="carousel-control-next-icon"></span>
  </a>
 
  {% endblock %}

weird! right?

0 items under this folder.