Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

django

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.

like image 772
pista329 Avatar asked Dec 24 '22 13:12

pista329


1 Answers

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.

like image 180
knbk Avatar answered Feb 08 '23 23:02

knbk