Django Environment

Coming soon.

Django Settings File

CodeRed Cloud looks for specific Django settings files when your app runs:

  • projectname/settings/prod.py for the Production environment.

  • projectname/settings/staging.py for the Staging environment.

We recommend that you create a projectname/settings/base.py file containing all of your main settings, and then override any environment-specific settings in prod.py or staging.py.

To work with CodeRed Cloud, your Django settings file should load a few important settings from environment variables. Below are the required settings.

Note

For enhanced security, your database password and permissions are reset automatically every time your app restarts. It is therefore impossible to hard-code those in your settings without using environment variables.

MariaDB Settings

Your MariaDB database requires SSL to connect, and is configured to use utf8mb4 character set and utf8mb4_unicode_ci collation by default. You should therefore also set the charset in your Django settings to avoid any potential issues when working with unicode characters, including emoji.

from .base import *  # noqa

# Required CodeRed Cloud settings

import os

ALLOWED_HOSTS = [os.environ['VIRTUAL_HOST']]

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': os.environ['DB_HOST'],
        'NAME': os.environ['DB_NAME'],
        'USER': os.environ['DB_USER'],
        'PASSWORD': os.environ['DB_PASSWORD'],
        'OPTIONS': {
            'ssl': {},
            'charset': 'utf8mb4',
        },
    }
}

PostgreSQL Settings

Your PostgreSQL database requires SSL to connect, and is set to use UTF8 character set.

from .base import *  # noqa

# Required CodeRed Cloud settings

import os

ALLOWED_HOSTS = [os.environ['VIRTUAL_HOST']]

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'HOST': os.environ['DB_HOST'],
        'NAME': os.environ['DB_NAME'],
        'USER': os.environ['DB_USER'],
        'PASSWORD': os.environ['DB_PASSWORD'],
        'OPTIONS': {'sslmode': 'require'},
    }
}