How do you configure Django for simple development and deployment?

Update: django-configurations has been released which is probably a better option for most people than doing it manually.

If you would prefer to do things manually, my earlier answer still applies:

I have multiple settings files.

  • – host-specific configuration, such as database name, file paths, etc.
  • – configuration used for development, e.g. DEBUG = True.
  • – configuration used for production, e.g. SERVER_EMAIL.

I tie these all together with a file that firstly imports, and then one of the other two. It decides which to load by two settings inside settings_local.pyDEVELOPMENT_HOSTS and PRODUCTION_HOSTS. calls platform.node() to find the hostname of the machine it is running on, and then looks for that hostname in the lists, and loads the second settings file depending on which list it finds the hostname in.

That way, the only thing you really need to worry about is keeping the file up to date with the host-specific configuration, and everything else is handled automatically.

Check out an example here.

Leave a Comment