How to Install and configure Django to render HTML Template in 3 steps (Video)

Let me get you through steps to install and configure Django server to render a HTML template. As you already know Django is a popular High-level Python Web framework using which you can build heavy User Interface/ Web application/Rest API. In this article, I will explain relevant configuration which required for you to get your web application working on Django.



Django is a high-level Python Web framework which follows model-view-template (MVT) architectural pattern. The framework is developed by web programmers Adrian Holovaty and Simon Willison and It was named after guitarist Django Reinhardt. You can develop powerful User Interface with robust design with Django. Django is based on high-level programming language Python which encourage a lot of Python developers to explore in Web development. It is a free and open-source Web framework and it is ridiculously fast, Reassuringly secure and exceedingly scalable. Django has largely adopted by Developers and DevOps to built various internal complex automation tools.

Explore the official documentation from here >>

Video tutorial:


[do_widget id=custom_html-12] Some stuffs from my personal experience. I have used Django in a lot of situations at my workplace. It was a special experience that I integrated Django with ReactJS and built beautiful and powerful user interface. Once you get used to Django, you will never let go off it.


Step1:  Install Django:

Let’s install and configure django for our WebApp. Install Django 1.9.3  as a python module using PIP  package manager.

user@ubuntu:~$ pip install Django==1.9.3

Note: We are using Python 2.7  here.


If you are getting any error saying ‘python is not installed’ or ‘pip is not installed’. Just try to run commands given below and try to fix the issue.

user@ubuntu:~$ sudo apt-get update              #update APT repository
user@ubuntu:~$ sudo apt-get install python      #Install Python
user@ubuntu:~$ sudo apt-get install python-pip  #Install PIP

If you are using CentOS and RHEL, please try with YUM  instead of APT .

user@ubuntu:~$ sudo yum update              #update YUM repository 
user@ubuntu:~$ sudo yum install python      #Install Python 
user@ubuntu:~$ sudo yum install epel-release 
user@ubuntu:~$ sudo yum install python-pip  #Install PIP


Step2: Create a Project and start the Django server:

Once you have django installed, let’s create an project named easyaslinux  with it.

user@ubuntu:~$ django-admin startproject easyaslinux

You will see a directory easyaslinux  is created. So change to the same directory and you should see again a directory easyaslinux  and  script.

user@ubuntu:~$ cd easyaslinux/
user@ubuntu:~/easyaslinux$ ls db.sqlite3 easyaslinux


At this point, you can start/run the Django server by running command given below.

user@ubuntu:~/easyaslinux$ ./ runserver
Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are applied.
Run 'python migrate' to apply them.

November 06, 2018 - 09:33:49
Django version 1.9.3, using settings 'easyaslinux.settings'
Starting development server at
Quit the server with CONTROL-C.


This means, the Django server is running is listening on port 8000 for incoming request. Let’s check it in the browser and you should get below page.


Step3: Configure Django to render Templates:

Create Templates:

It worked! You got Django working. But we are not done yet. Instead of “It worked” page, we need to show something our own in the browser. For that, we need to create templates which will get rendered to show what we want. Let’s create a directory called templates   and add two templates there.

user@ubuntu:~/easyaslinux$ cd easyaslinux/
user@ubuntu:~/easyaslinux/easyaslinux$ mkdir templates


In the ‘template’ directory create base.html  with following content.

<!doctype html>
<html  lang="en">
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="">
  <link rel="stylesheet" href="" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
  <script src=""></script>
  <script src=""></script>

    {% block main %}{% endblock %}


and sample_app.html  with following content

{% extends "base.html" %}

{% block main %}
<div class="container">
  <h1>Hello from</h1>
{% endblock %}


Basically, base.html is acting as a foundation for sample_app.html . Suppose you want something to be shown on every page (eg: head tag,website menus, frames, sidebars), you can add it in base.html  file.

I will tell you how this template stuff works. You can see that sample_app.html  extends content of base.html by mentioning {% extends “base.html” %}  . {% block main %}{% endblock %}  tag in base.html  says  that  content of this part is variable and we can easily assign content to it by adding the same inbetween {% block main %} and {% endblock %}  in sample_app.html .


Configure Django to render Templates:

We have our templates ready for our website. Now we should tell Django the directory location from where you load the templates. We can do this by modifying variable ‘TEMPLATES ‘ in . Just for your information,  is the heart of Django configuration. This is the place where you make Django level configuration changes.

'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'easyaslinux/templates')],    #added
'APP_DIRS': True,
'context_processors': [
},  },


We should also tell Django that for which URL this template should be rendered. And that we can do by adding two lines in  file.

from django.conf.urls import url
from django.contrib import admin
from django.views import generic    #added

urlpatterns = [
url(r'^$',generic.TemplateView.as_view(template_name='sample_app.html'))        #added


Just for your information, Files and directories structure of the project should look like this.

user@ubuntu:~/easyaslinux$ tree 
├── db.sqlite3
├── easyaslinux
│   ├──
│   ├── __init__.pyc
│   ├──
│   ├── settings.pyc
│   ├── templates
│   │   ├── base.html
│   │   └── sample_app.html
│   ├──
│   ├── urls.pyc
│   ├──
│   └── wsgi.pyc

2 directories, 12 files


Now go to your browser and you should see something like this. Don’t forget to start/run your Django server.

Congrats! You just configured Django to render a HTML template. You can start tweaking the template to give more style and content to your website. I have committed all files and directories to bring up this Django server to my Git repo. Please find it here >>

I will come back with a tutorial on “How to run Python, Perl, Ruby, Bash – any script with Django Views”. Please Subscribe  to this blog so that you don’t miss out anything useful (Checkout Right Sidebar for the Subscription Form) . Also put your thought on this article as a comment .


Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top