DJANGO
  • Django Static and Template Folders
  • Django Introduction
  • Django Getting Started
  • Django Migrations

Django Static And Template Folders



Static folders are folder that contains files which are always visible to the users like images , js , css files and other docs. We don't put any private files in static folder.

Template folders contains the html files that a user sees when they visit to the site.

Firstly create the folders static and template in the root project directory manually. After creating the folder we need to register the path of these created folders in settings.py file in our project directory.

To register the path of template folder find the TEMPLATES section  in settings.py file and add the path in DIRS:[ ] as shown below.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,"template")],
        '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',
            ],
        },
    },
]

For registering static folder search for STATIC_URL line (usually at the end of settings.py ) and add the following code in your settings.py file.

STATIC_URL = '/static/'
STATICFILES_DIRS=[
    os.path.join(BASE_DIR,"static")
]