0

In a Django project, the configuration is kept in a file called settings.py. Deployments will generally need to make local tweaks (such as setting LOCAL_HOSTS).

These tweaks cannot live in the local copy of settings.py, because it will confuse source control.

How can we resolve this?

1 Answer 1

0

Keep the local settings in a file localsettings.py in the same directory as settings.py.

Do not keep an actual localsettings.py in source control.

At the end of settings.py, add:

try:
    from project.project.localsettings import *
except ModuleNotFoundError:
    pass

This includes all the symbols from localsettings.py in settings.py, and the local symbols will have priority if there are any clashes. If localsettings.py doesn't exist, it does nothing.

And add the local settings file to .gitignore:

/project/project/localsettings.py

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.