Keeping local.py local

Noob question: presumably we add local.py to .gitignore so that the local settings (DEBUG=True etc.) are not pushed to Heroku and are only used locally?

I also assume adding local.py to .gitignore means that local.py will not be version controlled, but I suppose this does't matter?

Sorry You must be a logged in, registered user to answer a question.

Answers

Everybody seems to have a different way of doing this. I like version controlling my local settings, so I use an environment variable to trigger which settings are loaded.

import os
ENVIRONMENT = os.environ.get('ENVIRONMENT')
if ENVIRONMENT:
    exec('from settings_%s import *' % ENVIRONMENT)
else:
    from settings_dev import *

You can set environment variables on Heroku with heroku config:add ENVIRONMENT=production

Then keep a settings_production.py file traced in Git. Typically, my settings_production.py imports all of settings_dev.py and overrides the needed pieces.

Correct on both assumptions. Your local.py is only applicable to your local setup, and it doesn't need to be version controlled unless you plan on losing it.

You could always create a local.py.EXAMPLE and track it with Git, then, if you lost your local.py, you could rebuild it fairly quickly. Most of the time, though, your local.py doesn't have much in it, usually just DEBUG and DATABASES settings.

You would be correct. Adding local.py to the .gitignore will keep it from being version controlled. When you do a push to Heroku that file will never be included, which is what you want.

If you have a Dropbox account (or similar) and you're worried about losing the file, you could always keep your local.py file there and symlink it into the project. That way it is always backed up.