Django Separate local and global configuration

I was wondering if it was possible to separate the “local” configuration in Django (Local path to static, templates content which have to be absolute, local DB info, etc…) from the “global” configuration (URL, Middleware classes, installed apps, etc…) so that several people can work on a same project over Git or SVN without having to rewrite the local settings every time there is a commit done!


  • How to synchronize configuration between git setups?
  • Working with git behind proxy
  • Multiple diff Tools
  • Is there a way to override a git author's display name in local repository config?
  • Managing user configuration files across multiple computers
  • Branching strategy for configurable software
  • How do I create a branch and a pull request for a previous or old commit?
  • Git: Merge one folder inside a repo
  • Merging branches With Git
  • Git - remerging further down the line
  • Launch non-blocking process from powershell
  • how to find recent committers of a file in git?
  • 2 Solutions collect form web for “Django Separate local and global configuration”

    Yes, definitely. The file is just Python, so you can do anything in there – including setting things dynamically, and importing other files to override.

    So there’s two approaches here. The first is not to hard-code any paths, but calculate them dynamically.

    PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
        os.path.join(PROJECT_ROOT, "templates"),

    etc. The magic Python keyword __file__ gives the path to the current file.

    The second is to have a file outside of SVN, which is imported at the end of the main and overrides any settings there:

        from local_settings import *
    except ImportError:

    The try/except is to ensure that it still works even if local_settings is not present.

    Naturally, you could try a combination of those approaches.

    You can split up your configuration into different files. As they are written in python you’d just import the settings from the other settings file using import local_settings you even can put the import in a conditional to import local settings depending on some context.

    Take a look at the documentation:

    Git Baby is a git and github fan, let's start git clone.