1👍
✅
BASE_DIR + '../../../Data'
does not contains appropriate separate in between. Use os.path.join
there, too.
BTW, os.path.join
accepts multiple arguments. So you can write as follow:
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DATA_ROOT = os.path.join(BASE_DIR, '../../../Data', 'MyAppData')
# To get absolute path
DATA_ROOT = os.path.abspath(os.path.join(BASE_DIR, '../../../Data', 'MyAppData'))
To access the DATA_ROOT
in views, import settings
in the view:
from django.conf import settings
# Do something with `settings.DATA_ROOT`
UPDATE
If you use Python 3.4+, you can use pathlib
:
DATA_ROOT = pathlib.Path(__file__).resolve().parents[3] / 'Data' / 'MyAppData'
Source:stackexchange.com