On Django Settings…

Take some time to get to know your settings files in Django. They are the heart of your app, and can make your life very frustrating if you neglect them. I took ours for granted (after being babied for so long by Rails settings) and it came back to haunt me.

Probably the single most frustrating part of the template settings we used was figuring out where the settings directory paths were actually point.

Look at this confusing mess:


This sets the base directory to two levels above the current file path. Not necessarily easy to parse. This was a problem because with our file structure, the base actually needed three levels above, so that would mean wrapping this statement one more time. Not a great solution.

Luckily after some searching Nicole found a pretty cool library called unipath that made things a little easier to read.

Instead of that long confusing mess, we could whittle it down to this:

BASE_DIR = Path(__file__).ancestor(3)

Just looking at it, we know immediately that BASE_DIR is 3 levels above the current file. Much better!

After a little more refactoring, we managed to get our settings to a satisfactory place. Now we have a landing page and the beginnings of Meetup.Pizza!

Show your support

Clapping shows how much you appreciated Bjorn Johnson’s story.