In this tutorial, we will learn how to render static HTML pages in a Django application.

1. Technologies & Prerequisites

  • Python 3.7, 3.8
  • Django 3.1
  • HTML 5

2. Setup Django Environment

2.1 Virtualenv

The first step of beginning any python project is creating a virtual environment. Follow this tutorial to set up and activate a virtualenvand then install Django.

virtualenv env
source env/bin/activate
pip install Django

2.2 Setup Django Project

  • Start a Django project (here, project name:django_html) and create an app named home. Check this tutorial for more details.
django-admin startproject django_html
cd django_html/
python startapp home
Setting up project

2.3 Create HTML Page

Django uses templates to generate HTML dynamically. A template contains the static part as well some static syntax for displaying the dynamic content of the desired HTML page. Django has the Django template language for its own template system.

Create a directory named templates inside the newly created home apps directory.

By convention, Django’s template engine looks for a ‘templates’ subdirectory in each of the INSTALLED_APPS.

mkdir home/templates

Inside the templates dir, create a file named index.html with the following content.

<!DOCTYPE html>
<html lang="en">
    <title>Home Page</title>
    <h1>Home Page</h1>
    <p>This page is rendered as a Django Template</p>
    <h3>Happy Learning :)</h3>

2.4 Templates Configuration

2.4.1 Listing App

Add the name of the newly created app home to the INSTALLED_APPS list in

# Application definition


2.4.2 Templates Settings

Have a look at the TEMPLATES settings in the file, which contains the configurations for the templates engines and describes how Django will load and render templates.

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
  • BACKEND: Path to the default Django Template engine class.
  • DIRS: List of directories where the engine should look for source files, in given search order.
  • APP_DIRS: If True, the engine will look for templates inside installed applications.
  • OPTIONS: contains backend-specific settings.

We do not have to make any changes in these settings. As we have listed our app in the INSTALLED_APPS list, other things are taken care of by Django’s template engine.

2.5 Setup Views & URLs


Next, create a view in home/ for the template.

from django.shortcuts import render

def index(request):
    return render(request, 'index.html')

The index() method renders the HTML page. This is made possible using the render helper function from the django.shortcuts package.

Here, the render() function takes the request object and the template_name as the arguments and returns an HttpResponse object with the rendered text.


Create a file inside app directory home/ with the following content.

from django.urls import path
from . import views
urlpatterns = [
    path('', views.index),

Next, create a URL pattern for this app in the URL patterns for our project, ie. in the file django_html/

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('', include('home.urls')),

2.6 Run Project

Now, run the application using

python runserver

Navigate to http://localhost:8000/ and you can see the HTML page create being rendered.

Rendered HTML Page

3. References

Download Source from GIT:

Happy Learning 🙂