pythondjango

How to settings.py for different environments (dev, production, etc.)


I have a several environments for my project. DEV for development, BETA for beta testing, PRODUCTION for production deployment. Each of these environments share lot of settings, but have different databases.

I was wondering if there is any elegant solution to maintain settings.py for different environments without duplicating them in another settings.py file (e.g. using inheritance)

Thanks for your replies.


Solution

  • Setting files are just python modules. Often, the following structure is used:

    settings/
    |-- base.py
    |-- production.py
    |-- development.py
    

    Then, in your environment-specific settings, at the top of the file you import all common settings:

    from .base import *
    

    Then you point the DJANGO_SETTINGS_MODULE environment variable to the appropriate settings module.