In many tutorials they talk about PROJECT_PATH, but I don’t have it in my, neither I can find it in the official documentation. Is this depreciated? If not, how it should be defined?

I don’t know what tutorials you’re referring to, I don’t see that term being used in either the official Django tutorial or the Django Girls tutorial, and as you have mentioned, it’s not a setting referenced in the docs.

As a result, knowing that it’s not a standard settings and without knowing how those tutorials are using it, it’s not going to be possible to identify how it should be defined.

Let me explain what is going on.

I’m trying to avoid hardcoded links/paths in my project. Also I prefer to have one folder for “templates” and one for “static” shared between all apps.

After searching lots of documents and sites, I found this and this (and many others but I cannot post more than two links here) talking about SITE_ROOT and PROJECT_ROOT.

I have created a variable in my as this:

SITE_ROOT = os.path.abspath(os.path.dirname(file))

And used it like:

DIRS = [os.path.join(SITE_ROOT, ‘templates’),],
STATICFILES_DIRS = [os.path.join(SITE_ROOT, ‘static’)]

Both work perfectly for me.

My question is, am I reinventing the wheel here? Is there any built-in variable to use instead of defining my own SITE_ROOT?

Yes, you’re (kind of) reinventing the wheel.

No, there’s no “formal” defined parameter for this.

The standard Django startproject management command creates a variable named BASE_DIR which serves the same purpose. But again, it is not a formal settings. There’s nothing special about that name, it’s just what was chosen at the time that command was written.

Correct me if I am wrong but:

BASE_DIR points to the top-level project folder (where is) and
SITE_ROOT (the way I defined it) points to “project folder/project name” where “templates” and “static” folders are; and that’s what I needed.

No, you’re right on that. Clearly, you’re familiar with your deployment environment, and so I’m going to assume that there are specific reasons why you’re choosing to do things that way and why. So if it works for you, have at it.

1 Like