Provision settings.py File

Details for various sections of settings.py file are as follows

Database Settings
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, '../Project_DB/db.sqlite3'),
        'DATABASE_OPTIONS':{'timeout': 05}
    }
}
Installed Apps

We can create new app in django project using the following command

(my_env) mysite$ django-admin startapp my_app

TODOs folder structure of app

Once the app is created, it needs to be registered in settings.py file before using it in a project. App registration is done as follows

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'my_app'
]
HTML templates Folder

Main purpose of template folders is to store the HTML templates. We can have one or many template folders in a django project. Django keeps track of all the template folders centrally in settings.py file

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['html_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',
            ],
        },
    },
]

Each django app can have directory named templates inside it, which serves the same purpose as above mentioned html_templates directory. We dont have to register these directories in settings.py file though as django expects them by default because of 'APP_DIRS': True line above.

Timezone
TIME_ZONE = 'Asia/Kolkata'
Static Folder

Static folder holds the usual static files viz. images, .js files, .css files etc. We can have more than one static file directories.

STATIC_URL = '/static/'

STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
Media Folder

Media folder holds all the uploaded files and images

MEDIA_URL = "/Media/"

MEDIA_ROOT = os.path.join(BASE_DIR,"Media")

Deep dive into settings.py ...

results matching ""

    No results matching ""