Skip to main content
DjangoKit Log In

Settings

By default, DjangoKit projects don't include a Django settings module! This is because we generally prefer convention over configuration.

Page Navigation

Default Settings

The default settings for a DjangoKit project are in the module djangokit.core.settings.

Project Settings

Additional configuration needed by your project can be added to env-specific settings:

  • settings.public.toml - base configuration for you project stored in version control - should not include any sensitive values
  • settings.development.toml - development settings
  • settings.production.toml - production settings
  • settings.<arbitrary>.toml - settings for any arbitrary environment (e.g., staging)

Warning

In general, avoid adding your env-specific settings files to version control (except in special cases).

In production, you may want to use environment variables (see below) or some other means to inject sensitive settings.

Django Settings

You can set any Django setting in your project settings files in the [django] section:

# settings.development.toml
[django]
DEBUG = true
SECRET_KEY = "super-secret-key"

DjangoKit Settings

DjangoKit has a handful of settings you can use to customize your project. The most important of these is the package setting, which should be added to your project's settings.public.toml file:

# settings.public.toml

[djangokit]
package = "my_package"  # <- this is required; the rest of the DjangoKit settings are not
title = "My Project"
description = "My project is v. cool"
global_stylesheets = ["bootstrap.css", "pygments.css", "global.css"]

Accessing the DjangoKit Settings in Your Code

DjangoKit settings are accessed via the top level DJANGOKIT setting. Note that DJANGOKIT is an object and its subsettings are accessed via dot notation. Additionally, DjangoKit always sets all of it settings, so they can always safely be accessed.

from djangokit.conf import settings

def get(request):
    settings.DJANGOKIT.package  # -> 'my_package'

Reading Settings from Environment Variables

To specify that a setting should be read from an environment variable, use the [django.from_env] and/or [djangokit.from_env] sections in your public settings file:

[django.from_env]
DATABASES.default.NAME = "DJANGO_DATABASE_PASSWORD"

The left side is the dotted path of the setting and the value is the name of the environment variable the setting should be loaded from. When environment variables are loaded they will be parsed as TOML values if possible. So you can set env vars to values like 1 or true and they will be automatically converted to int and bool respectively.

Using an Additional Settings Module

If you have some custom base settings that are too complex to define in a TOML file, you can define them in an additional settings module. These additional settings will augment/override the default Django settings provided by DjangoKit, but settings files and env vars will still take precedence.

To specify an additional settings module, use the DJANGO_ADDITIONAL_SETTINGS_MODULE environment variable and point it at the module:

export DJANGO_ADDITIONAL_SETTINGS_MODULE="myproject.additional_settings"

When using the DjangoKit CLI, you can use the --additional-settings-module option.

Using a Standard Settings Module

TODO

This section needs to be updated with regard to the DJANGOKIT settings--it must be an object.

If your project's settings are extra complex or you just want to go with the standard Django approach to settings, you can add a settings module to your project and ignore most of the above. In this case, you'd add all the standard Django settings plus your DjangoKit settings:

# settings.py

DJANGOKIT = {
    "package": "my_package",
}

NOTE: You can "eject" from the TOML settings approach altogether by running dk show-settings and copying the output to your Django settings module.

Viewing Settings

You can use the DjangoKit CLI to view your settings:

# Show DjangoKit default settings plus your project settings (excludes Django defaults)
dk show-settings

# Show *all* the settings (includes Django defaults)
dk show-settings --all

# Show a single setting or settings matching a pattern
dk show-settings --only DATABASES