How do I activate database settings from my settings.py DATABASES array based on environment?

How do I activate database settings from my settings.py DATABASES array based on environment?

I'm using Django with Python 3.7. I have a settings.py file, which includes some database settings ...

I'm using Django with Python 3.7. I have a settings.py file, which includes some database settings ...

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'mainpage',
        'USER': 'mainpage',
        'PASSWORD': 'password',
        'HOST': 'localhost',
        'PORT': '5432'
    },
    'production': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'mainpage',
        'USER': 'mainpage',
        'PASSWORD': 'password',
        'HOST': 'localhost',
        'PORT': '5432'
    }
}

The file includes a bunch of other things but I have only included the database array here. Is it possible to activate a particular database configuration from my array based on my environment or an environment variable? I would prefer not to have multiple settings files because then I have to repeat a lot of other configurations in them that do not change across environment. I'm happy to move the database settings to their own files if that's what it takes but I'm not sure how they would be activated.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Python Django Tutorial | Django Course

🔥Intellipaat Django course: https://intellipaat.com/python-django-training/ 👉This Python Django tutorial will help you learn what is django web development &...

Django Database Migrations: A Comprehensive Overview

Django Database Migrations: A Comprehensive Overview *by Damian Hites* The Django web framework is designed to work with an SQL-based relational database backend, most commonly PostgreSQL or MySQL. If you’ve never worked directly with a...