Software Development

What is the best strategy for managing Django settings across Dev, Staging, and Production?

CH Asked by Christopher Lee · 21-09-2025
0 upvotes 15,667 views 0 comments
The question

My settings.py file is becoming a mess of if-else statements to handle different database URLs and debug flags. I've seen people use a 'settings' folder with multiple files like base.py and production.py, but I've also heard that environment variables are the "modern" way. Which approach is more scalable for a team of 5 developers using Docker and CI/CD pipelines?

3 answers

0
PA
Answered on 22-09-2025

We use a settings directory with base.py and local.py. We add local.py to .gitignore so every dev can have their own custom database credentials without breaking the repo.

CH 27-09-2025

I used to do that, Patricia, but I've found that environment variables are much easier to manage once you move into containerized environments like Docker.

0
MA
Answered on 23-09-2025

The best practice in 2024 is a hybrid approach: use a single settings.py file that pulls almost everything from environment variables using a package like 'django-environ' or 'python-dotenv'. This follows the "12-Factor App" methodology. By having one file, you avoid the "where did this setting come from?" headache that occurs with deep inheritance in a settings folder. You can provide a .env.example file for local development and inject the actual production values via your CI/CD secrets manager like GitHub Actions or AWS Secrets Manager.

0
DA
Answered on 25-09-2025

Do you find that using a single file makes the imports section too cluttered, or does the clarity of seeing all variables in one place outweigh that?

TH 26-09-2025

David, the clarity is definitely the winner here. When you use env.db() or env.bool(), the intent is very clear. If a teammate needs to know how the cache is configured, they look in one place. Splitting into base/prod/dev files often leads to "shadowing" where a variable is defined in two places and you accidentally use the wrong one because of the import order. Stick to one file and keep it clean with comments.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session