top of page

How to add static files in django projects | How to add 'html' files and static(js,css,imag

Updated: Mar 18, 2021

To add static files(css, js files, images) some basic changes are made in django files as per given below code files:

First we create html file by creation directory 'templates' in our in app folder like this:

And then after create html files(index.html). Go to the file and make changes in this file like this:

TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ]

After adding this code

TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR,'TEMPLATES')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ]

Create another directory static in Appfolder(helloworld) in create any static files(like css, js, image) inside it:

Add css file:

To insert CSS file in project first create a directory in main project folder whose name is static. After that some changes are made to run the code.

First add this load code at the top of of index.html page:

<!DOCTYPE html> {% load static %} <html lang="en"> <head>

After this go to the and changes in the static part which is located at the last in the file:

# Static files (CSS, JavaScript, Images) # STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR,'static') ]

And run the project.

Project 1:

Print Hello world:

First set path in

from django.contrib import admin from django.urls import path from helloworld.views import Hello urlpatterns = [ path('admin/',, path('helloworld/',Hello) //set path ‘helloword/’and pass Hello



After set path in make changes in file.

from django.http import HttpResponse def Hello(request): //add method hello return HttpResponse("Hello")

# Create your views here.

Add app name to the file:

INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'helloworld', //app name ]

If you like Codersarts blog and looking for Assignment help, Project help, Programming tutors help and suggestion you can send mail at

#Howtoaddcssfileindjangoprojet #Djangoassignmenthelp #Djangoprojecthelp #Djangohomeworkhelp #Howtocreatedjangoapp #createdjangoapp #Djangohelpinusa #Howaddstaticfilesindjango

bottom of page