Python Forum

Full Version: paths in django 'settings.py'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
in a new django-project in the file 'settings.py' we will find the first line of code:
   BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
the comment above this line of code says:
'# Build paths inside the project like this: os.path.join(BASE_DIR, ...)'

down the code the object 'BASE_DIR' is used (mentioned) just one more time in the 'DATABASES' dict-data-type object:
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
} 
as i understand the object 'BASE_DIR' will contain the path to the data-base of the future website. but what will happen if we edit the code like this (for example):
BASE_DIR = /home/tony/python-project/ ... data-base 
what is the purpose of using the 'os-module'?
do i correctly understand that the line ...
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
will create a data-base for the website automatically with the name 'BASE_DIR' so there will be no need for me to write a data-base for the website manually?