Reputation: 645
This is my folder structure.
I want to set BASE_DIR in production.py file.
In older version of Django this is how we used to set the BASE_DIR:
From:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
To:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
But in latest version of Django we "Path" to set BASE_DIR
From:
BASE_DIR = Path(__file__).resolve().parent.parent
To:
???
So how to set BASE_DIR for above folder structure
Upvotes: 2
Views: 1406
Reputation: 2045
It should be
BASE_DIR = Path(__file__).resolve().parent.parent.parent
You can think of .parent
as os.path.dirname
, it has the same effect,
in older versions you used dirname
3 times, you can replace it with 3 .parent
while using pathlib.Path
object.
Upvotes: 3