Aakash Solanki
Aakash Solanki

Reputation: 645

How to set BASE_DIR for the Production Settings in Django 3.1.4?

This is my folder structure.

enter image description here

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

Answers (1)

Radwan Abu-Odeh
Radwan Abu-Odeh

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

Related Questions