Django – Extending templates

Name of Innovation

Django – Extending templates

September 25, 2019 Uncategorized 0
wordcount/wcount/templates/wcount/base.html

<html>

    <head>

        <title>WOIR Software</title>

        <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

        <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">

        <link href='//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext' rel='stylesheet' type='text/css'>

    </head>

<body>

    <div class="page-header">

        <h1><a href="/">Our Page</a></h1>

    </div>

    <div class="content container">

        <div class="row">

            <div class="col-md-8">

            {% block content %}

            {% endblock %}

            </div>

        </div>

    </div>

</body>

</html>





wordcount/wcount/templates/wcount/about.html
{% extends 'wcount/base.html' %}

{% block content %}

<h1> About us from template file.</h1>

{% endblock %}

wordcount/wcount/templates/wcount/count.html

{% extends 'wcount/base.html' %}

{% block content %}
<h1> I will count the value for you.</h1>

{% endblock %}

wordcount/wcount/templates/wcount/home.html
{% extends 'wcount/base.html' %}

{% block content %}

<h1> Home page template file.</h1>

{% endblock %}

 
wcount/views.py

from django.http import HttpResponse

from django.shortcuts import render

import operator




def home(request):

 return render(request, 'wcount/home.html')




def about(request):

 return render(request, 'wcount/about.html') 

def count(request):

 return render(request, 'wcount/count.html')


wordcount/urls.py
from django.contrib import admin

from django.urls import path

from wcount import views

urlpatterns = [

    path('admin/', admin.site.urls),

    path('', views.home, name='home'),

    path('about/', views.about, name='about'),

    path('count/', views.count, name='count'),

]