Django Templates


Django Templates Tutorial

Let’s build a basic page using Django’s rendering system to return an HTML layout.


Make a Design Folder

Inside your Django app directory (members/), create a folder named templates, and inside it, add a file called firstpage.html.

Your structure should now look like:

my_tennis_club/ 
│ 
├── manage.py 
├── my_tennis_club/ 
└── members/     
        └── templates/         
                └── firstpage.html 

Add Some Markup

In the newly created file firstpage.html, paste this content:

<!DOCTYPE html> 
<html>   
     <body>      
           
          <h1>Hi, visitor!</h1>     
          <p>This is my starter page built with Django.</p>    

     </body> 
</html>

Update the Logic File

Go into views.py inside your members/ folder and change it to:

from django.http import HttpResponse 
from django.template import loader  

def member_page(request):     
       design = loader.get_template('firstpage.html')     
       Return HttpResponse(design.render()) 

This function loads the HTML from your template folder and returns it as a webpage response.


Connect the App in Configuration

To let Django know about the app, open settings.py (inside my_tennis_club/) and look for INSTALLED_APPS.

Add 'members' to the list like this:

INSTALLED_APPS = [     
    'django.contrib.admin',     
    'django.contrib.auth',     
    'django.contrib.contenttypes',     
    'django.contrib.sessions',     
    'django.contrib.messages',     
    'django.contrib.staticfiles',     
    'members',  # <-- Add this line 
] 

Apply Migrations

Now apply database setup commands:

python manage.py migrate

Expected output will include:

Applying admin.0001_initial... OK 
Applying auth.0001_initial... OK ... 

Applying sessions.0001_initial... OK

Each "OK" means part of the setup was successful.


Start the Local Host Server

Navigate to the main directory:

cd my_tennis_club

Run the development server:

python manage.py runserver

Then, open your browser and visit:

http://127.0.0.1:8000/members/

If everything’s in place, your custom HTML page will appear.


Prefer Learning by Watching?

Watch these YouTube tutorials to understand HTML Tutorial visually:

What You'll Learn:
  • 📌 #5 Django tutorials | Django Template Language | DTL
  • 📌 Python Django App & Templates tutorial
Previous Next