Templates and Static Directory Setup in Django

A Django beginner sometimes faces to setup templates and static directories in their project. Since different youtube tutorials and blogs set up these directories in different ways, confusion arises accordingly. Today, I will show you a very easy way to minimize zero-level confusion.

Templates Directory setup:

Templates directory/folder contains html files.

Step-1: create a directory named “templates” under your project

Step-2: Go to setting file and update the below line just writing templates in DIRS”: [ ]

TEMPLATES = [
    {
        . .. . . . 
        "DIRS": ['templates'],
          . . . . .
            ],
        },
    },
]

Static directory setup:

Static directory contains css, javascripts and images files.

Step-1: create a directory named “static” under your project

Step-2: Go to setting file and write the below lines at the end of the file

import os
STATICFILES_DIRS = [
    os.path.join(BASE_DIR,'static')
]

The directory structures will be as follows:

Myproject
—-Myapp
—-Myproject
—-templates
—-db.sqllites
—-manage.py
—-static

Leave a Reply

Your email address will not be published. Required fields are marked *