9👍
There is an alternative, probably more flexible approach to this. Don’t exclude the settings.py
file.
Instead, do something like this:
try:
from localsettings import *
except ImportError:
pass
That way, if you ever need to actually change your settings.py
file, others can pick up the changes. You can supply reasonable defaults, so long as any settings you may want to override locally are above the localsettings
import.
You can change your localsettings.py
file as much as you need (I tend to use it for turning on DEBUG
, setting my database settings, and making sure I’m just using local memory as my cache backend).
Just make sure you exclude the localsettings.py
file from your commits.
2👍
The way this is most generally done with Mercurual is to commit a file called something like settings.py.template
, and have the first step someone takes on a new clone be to copy that over to a settings.py
file, which is listed in the .hgignore
file. That way, if someone adds a new settings in the template people will still get it and can merge it into their local settings. It’s easy to automate the copying of template to actual in your start/deploy script or using a clone hook, though most folks don’t bother.
- [Django]-How can i find if the date lies between two dates
- [Django]-Django REST Framework's APIClient sends None as 'None'
- [Django]-Save user with generated password with Django
- [Django]-User permissions for Django module
0👍
I know this is an old thread, but others might find a different approach still useful. (I came across this SO asking the same question).
You can keep settings.py in the repository and modify it to get machine specific values from enviornment variables. this is suggested here and here
As example would be the DB connection that often differ from one machine to another:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['DB_NAME'],
'USER': os.environ['DB_USER'],
'PASSWORD': os.environ['DB_PASSWORD'],
'HOST': os.environ['DB_HOST'],
'PORT': os.environ['DB_PORT'],
} }
- [Django]-Unique together in Django User Model
- [Django]-Showing auth_message's
- [Django]-Testing a Django app in many separate threads