DEV Community

Suri Nuthalapati
Suri Nuthalapati

Posted on

How to manage Local vs Dev vs Prod settings.py in latest Django RestAPI?

Django Best Practices

As we have some common settings in both Local, Dev, and Prod settings, and also have settings that are different from Local, Dev, and Prod; such as database connections, installed apps, etc...I would like to start my Django app with custom settings_.py file for each environment so that we can have better visibilty in settings and also will not cause git conflicts....

Top comments (8)

Collapse
 
thecal714 profile image
Sean Callaway

I'd take a look at this article for how to setup multiple settings modules. However, I do use environment variables (DJANGO_SETTINGS_MODULE) to load the correct one in CI and in Docker containers.

Collapse
 
thammuio profile image
Suri Nuthalapati

this article Worked for me. Thank you..

Collapse
 
thecal714 profile image
Sean Callaway

Glad to hear it!

Collapse
 
thammuio profile image
Suri Nuthalapati

Thanks I will test out this link and update on how it goes..

Collapse
 
cbrintnall profile image
Christian Brintnall

I used to run a small website for my campus's library employees ran with Django. So take this with a grain of salt.

We would keep all common settings in a settings.py and then have a nonprod_settings.py and prod_settings.py. You can then point to the environment specific settings.py with:

export DJANGO_SETTINGS_MODULE=<nonprod/prod>_settings.settings.

For common settings, at the bottom of our environmental settings we would from common_settings import *.

Info here: https://docs.djangoproject.com/en/2.1/topics/settings/.

Collapse
 
jacksonelfers profile image
Jackson Elfers

Not an avid django/python user but maybe consider keeping local, dev and prod in .env files and passing the variables into the settings.py file. That way any sensitive info is kept consistently in key value pair files and can be easily swapped. Might be inaccurately prescribed, it comes from node.js tinkering. Best of luck. 😁

Collapse
 
haruanm profile image
Haruan Justino

We are using os.getenv method and working with .env files to set the enviroment data, works pretty well.

Collapse
 
thammuio profile image
Suri Nuthalapati

this article worked for me. If anyone is still looking for a solution...