Django | Build a Dashboard with Django and Bootstrap: Part 1

This is Part 1 of Building a Dashboard with Django and Bootstrap:


Building a complete web app isn’t always an easy task. Designing and Implementing on both sides (backend and front-end) requires mostly a lot of knowledge. So, why don’t using tools or framework, which helps and makes our life easier. Django is one of these frameworks:

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development

So, let’s get started.

Create project

For subsequent steps, we will remember our starting directory

... here you will see your current folder...

First step is to create our main Django project

> django-admin startproject dashboard
> cd dashboard
> python migrate
> python runserver 8080

Starting development server at
Quit the server with CTRL-BREAK.

View current project in browser

Create first apps

mkdir -p apps/core
python  startapp Core apps/core

mkdir -p dashboard/apps/frontend
python createapp Frontend dashboard/apps/frontend

Add new apps to project

Modify name in apps/core/

class CoreConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'apps.core'

Modify name in apps/frontend/

class FrontendConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'apps.frontend'

Modify dashboard/



Modify dashboard/

from django.urls import path

import dashboard.apps.frontend.views as views

urlpatterns = [
    path('', views.IndexView.as_view(), name='index'),

Create view

Modify view in apps/frontend/

from django.shortcuts import render
from django.views import generic

class IndexView(generic.TemplateView):
    module = 'indexView'
    template_name = 'frontend/index.html'

Create template for frontend View

Create template file dashboard/apps/frontend/templates/frontend/index.html

Frontend: Let's get started

Add template folder to configuration

Add template folder to TEMPLATES

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],


View current project in browser

Current folder Structure

So far, we have the following folder structure

Prepare for administrate your project

Create admin user

python createsuperuser
Username (leave blank to use 'user'): admin
Email address: admin@localhost
Password (again): 
Superuser created successfully.

Add Bootstrap support

Download requires files for Bootstrap, jQuery and PopperJS.

Or download this prepared archiv aund unzip the files unter dashboard.

$ROOT = Split-Path -Parent $PSSCRIPTROOT

$global:ProgressPreference  = 'SilentlyContinue'  
$response = Invoke-WebRequest 
$downloadlink = $response.links | Where-Object { $_.href -like "*download/" } | foreach-object { $_.href } | select-object -first 1 
$downloadpage = Invoke-WebRequest$downloadlink

$dist_download_url = $downloadpage.links | where-object { $_.href -like "*" } | foreach-object { $_.href }
$dist_version      = $dist_download_url.split("/")[-2].replace("v","")
$dist_zip          = "$ROOT\${dist_version}.zip"

write-host "Download $dist_zip from $dist_download_url"
Invoke-WebRequest $dist_download_url -O $dist_zip

write-host "Unpack to assets\vendor\bootstrap\${dist_version}"
remove-item -recurse -force               static\assets\vendor\bootstrap
new-item -type directory                  static\assets\vendor\bootstrap > $null 
expand-archive $dist_zip -destinationpath static\assets\vendor\bootstrap

move-item static\assets/vendor/bootstrap/bootstrap* static\assets\vendor\bootstrap\${dist_version}

$global:ProgressPreference  = 'Continue'
$ROOT = Split-Path -Parent $PSSCRIPTROOT

$version = "3.6.0"

$url_base = ""

$destination = "static\assets\vendor\jquery\$version\js"

write-host "Prepare  destination $destination"
remove-item -recurse -force               $destination > $null 
new-item -type directory                  $destination > $null 

Invoke-WebRequest $url_base/jquery-3.6.0.js      -O $destination/jquery-3.6.0.js
Invoke-WebRequest $url_base/ -O $destination/
$ROOT = Split-Path -Parent $PSSCRIPTROOT

$version = "2.10.2"

$url_base = "${version}/umd/"

$destination = "static\assets\vendor\popperjs\$version\js"

write-host "Prepare  destination $destination"
remove-item -recurse -force               $destination > $null 
new-item -type directory                  $destination > $null 

Invoke-WebRequest $url_base/popper.js      -O $Destination/popper.js

Finally, the folder structure should look like this:

Create site templates in dashboard/templates/site

Add templates path to settings

File dashboard/

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            BASE_DIR + '/dashboard/templates',

Add static path to settings

File dashboard/

STATIC_URL = '/static/'
    os.path.join(BASE_DIR, '/static')

Modify frontend view template

File dashboard/apps/frontend/templates/index.html

{% extends 'site/base.html' %}
{% load static %} {% block title %}Dashboard with Django and Bootstrap{% endblock title %}
{% block nav-style %}mkt-nav{% endblock nav-style %}

{% block content %}
<div class="jumbotron">
	<div class="container"></div>
	<div class="container full"></div>
{% endblock content %}

View current status of project

Add dashboard from an existing template

For a first start, we will use this sb-admin-2 dashboard template from here:

Download required files

Bootstrap templates consist of at least 3 different types of files

  • main index.html page, responsible for collection all elements and set up your page
  • CSS files defining the style of your page
  • JavaScript files, containing needed frameworks and code

So, first start by downloading the sample template from here. Be sure, you start in our project root folder:

git clone install/sb-admin-2

Next, find out, what we need for our template in addition to the file index.html

cd install/sb-admin-2
grep -E "<(link|script)" index.html 
  <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
  <link href=",200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
  <link href="css/sb-admin-2.min.css" rel="stylesheet">
  <script src="vendor/jquery/jquery.min.js"></script>
  <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="vendor/jquery-easing/jquery.easing.min.js"></script>
  <script src="js/sb-admin-2.min.js"></script>
  <script src="vendor/chart.js/Chart.min.js"></script>
  <script src="js/demo/chart-area-demo.js"></script>
  <script src="js/demo/chart-pie-demo.js"></script>

That’s a lot of additional files.

To keep the file structure consistent, these files should be stored under the dash/board/static folder (same as the bootstrap files before).

To achieve this, there are two possibilities:

  • Create desired folder and copy each of the source files to the destination folder
  • Copy the complete static folder from the github repository for this post.

We use the second option to keep the focus on creating our dashboard.

So, first, clone the repository:

cd $DASHBOARD_ROOT/install
git clone

Then, copy the requred files

cp -R install/Dashboard_Django-Bootstrap/dashboard/static dashboard
cp -R install/Dashboard_Django-Bootstrap/dashboard/templates dashboard

Having everything needed for the dashboard template, the next step is to modify the front-end template

File dashboard/apps/frontend/templates/frontend/index.html

{% extends 'site/sb-admin-2/base.html' %}
{% load static %} {% block title %}Dashboard with Django and Bootstrap{% endblock title %}

{% block content %}
{% endblock content %}

View current project in browser

Perfect. We are done with the basic setup.

Still some work to do, because our dashboard is only a static dashboard. All content is programmed in the dashboard template file dashboard/templates/site/sb-admin-2/base.html

For example, look at the cards with the earnings at the top:

To achieve a more dynamic content, we need to move the desired parts of the dashboard from the template file to the front-end view file.

This will be described in the next step: Part 2: Prepare for dynamic content

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

de German