3

I am currently setting up my settings files for Django 1.10 as per Two Scoops For Django 1.8 preferred settings files set up.

my base.py settings file is:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

the BASE_DIR is returning the following path:

/Devs/projects/captain_log/src/cap_log

my file tree:

|--Virtual Env Folder
    |--src(django project)/
       |--cap_log(django config)/
          |--init.py
          |--urls.py
          |--wsgi.py
          |--settings/
              |-- init.py
              |-- base.py (all settings located here)
              |-- development.py
              |-- production.py
              |-- etc.

I am under the assumption that the BASE_DIR is supposed to return:

/Devs/projects/captain_log/src/

I am asking because my STATIC_DIRS is also returning:

/Devs/projects/captain_log/src/cap_log/static

instead of:

 /Devs/projects/captain_log/src/static

Can someone please advise to a solution or correction to what I am doing. It is also effecting template paths, collectstatic, Media Path, etc.

Corey Gumbs
  • 372
  • 6
  • 13

1 Answers1

7

Try one more dirname call

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

The first dirname gives you settings, the second gives you the config folder, the third will put you in the parent directory

__file__ # is the current file location
os.path.abspath(__file__) # locates you on the file structure
os.path.dirname(os.path.abspath(__file__)) # gives you the directory of the file at the supplied filepath

The default assumption is you are using a settings.py file rather than a directory, so you are one directory shallow in the original config

Selecsosi
  • 1,636
  • 19
  • 23
  • Thank you. That worked. I don't know why I didn't think of that. – Corey Gumbs Oct 19 '16 at 00:58
  • I moved my settings.py file into a settings/ folder to hold all my setting files. And all hell broke loose. Adding one more `os.path.dirname` to the existing value fixed it for me. `BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))` – Vineeth Sai Feb 05 '19 at 11:06