How to do it...

Follow these steps to configure project settings:

  1. In the myproject directory, create a config Python module with the following files:
    • __init__.py
    • base.py for shared settings
    • dev.py for development settings
    • test.py for testing settings
    • staging.py for staging settings
    • prod.py for production settings
  2. Put all of your shared settings in config/base.py.
  3. If the settings of an environment are the same as the shared settings, then just import everything from base.py there, as follows:
# myproject/config/prod.py
from .base import *
  1. Apply the settings that you want to attach or overwrite for your specific environment in the other files, for example, the development environment settings should go to dev.py, as shown in the following:
# myproject/config/dev.py
from .base import *
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
  1. At the beginning of myproject/settings.py, import the configurations from one of the environment settings and then additionally attach specific or sensitive configurations, such as DATABASES or API keys that shouldn't be under version control, as follows:
# myproject/settings.py
from .config.dev import *

DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "myproject",
"USER": "root",
"PASSWORD": "root",
}
}
  1. Create a settings.py.example file that should contain all the sensitive settings that are necessary for a project to run, however, with empty values set.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.104.29