Configuration#
This page describes fairdm.setup(): its arguments, the environment it resolves, the five layers it applies, the environment files it reads and the command that shows what it did. It does not list the settings, which are in Settings, or explain why the layers are ordered as they are, which is in How FairDM configures a portal. The checks that stop a production portal from starting are in Configuration checks.
fairdm.setup()#
fairdm.setup(
apps: list[str] | None = None,
addons: list[str] | None = None,
base_dir: Path | None = None,
env_file: str | None = None,
) -> None
A portal’s settings module calls it once. It fills the calling module with a complete Django configuration and returns nothing.
# config/settings.py
import fairdm
fairdm.setup()
Argument |
Type |
Default |
What it does |
What it accepts |
|---|---|---|---|---|
|
|
|
The portal’s own apps. FairDM places them in |
App module paths or app configuration paths |
|
|
|
The addon packages whose settings FairDM applies as layer 3. |
Importable package names. See Addons. |
|
|
The directory above the one holding the calling settings module |
The directory FairDM looks in for the environment files, |
A |
|
|
|
An environment file read last, which overwrites variables already set. A path that does not exist is ignored. |
A file path |
setup() accepts no settings as arguments. Passing any other keyword argument raises TypeError. A setting changes by assignment after the call, as How to override a FairDM setting shows.
setup() raises ImproperlyConfigured when an addon’s setup module cannot be found or fails while DJANGO_ENV is production. It raises SystemCheckError when PARLER_LANGUAGES names a language that LANGUAGES does not include.
setup() adds four names to the calling module besides the settings:
Name |
What it holds |
|---|---|
|
The django-environ reader FairDM uses. A layer can call |
|
The |
|
The |
|
The resolved environment name |
The resolved environment#
FairDM takes the environment from the DJANGO_ENV environment variable and uses production when it is unset. It does not check the value against a list. Any name is valid, including a name no override module exists for.
FairDM ships one override module, for development. Every other name composes the production baseline, and a production portal checks that baseline at start-up. Only the exact value development skips the production-critical checks.
Layers#
setup() applies five layers in this order. A later layer overrides the same setting in an earlier one.
Layer |
Source |
Selected by |
|---|---|---|
1. Baseline |
Every module under |
Always applied |
2. FairDM override |
|
The file exists. Only |
3. Addons |
The setup module of each addon in |
The addon defines |
4. Portal override |
|
The file exists |
5. Portal assignments |
Assignments in the portal’s settings module after the call |
Always applied |
A layer chosen by existence is skipped without error when its file is missing. If the settings module has no file on disk, FairDM skips layer 4 and logs a warning.
If FairDM and the portal both have a module for the environment, both apply, FairDM’s first. How to add an environment override module shows how to add one.
Baseline modules#
The baseline loads these modules in this order, and a module may read names an earlier one defined.
Module |
What it owns |
|---|---|
|
|
|
|
|
|
|
|
|
Static files, media storage and thumbnails |
|
The |
|
Authentication backends, allauth, sign-in and profile forms |
|
|
|
The email backend and addresses |
|
Settings for other packages, identifiers, markdown, the page shell and branding. This is a settings module and not the addon loader. |
|
The REST framework, OpenAPI and CORS settings |
Settings groups the settings by subject.
Addons#
An addon is a package that contributes settings. FairDM imports each package named in addons= and looks for the module path in the package’s __fdm_setup_module__ attribute. That module must be a single file and not a package. FairDM runs it in a private copy of the settings and merges the result only when the module runs to the end, so a module that fails leaves nothing behind.
Situation |
In production |
In any other environment |
|---|---|---|
The package cannot be imported |
Logs an error and skips the addon |
Logs an error and skips the addon |
The package has no |
Logs a warning and skips the addon |
Logs a warning and skips the addon |
The setup module cannot be found |
Raises |
Logs a warning and skips the addon |
The setup module raises while it runs |
Raises |
Logs a warning and skips the addon |
setup() applies an addon’s settings and nothing else. An addon adds its apps and middleware by assigning INSTALLED_APPS and MIDDLEWARE in its setup module, and the portal includes the addon’s URLs in its own URLconf.
How to create an addon shows how to write one.
Environment files#
Before FairDM applies any layer, it reads environment files with django-environ. They are looked up in base_dir, and they are read in this order.
Order |
File |
Overwrites a variable that is already set |
|---|---|---|
1 |
|
No |
2 |
|
No |
3 |
The file named by |
Yes |
A variable already set in the process environment therefore beats the first two files. Only the explicit env_file overwrites it, and it also overwrites variables the two earlier files set. Each file holds one NAME=value per line. Settings lists the variables.
show_config#
python manage.py show_config [SETTING]
Form |
What it prints |
|---|---|
|
One line for each layer |
|
|
The command reports layers 1 to 4. An assignment in the portal’s settings module after the setup() call is not a layer it records, so for a setting you assign there it names the layer that set the value before your assignment, or unattributed.
Boot checks#
When the settings in force are the production baseline, FairDM runs its production-critical checks as the portal starts and stops the portal if one fails. python manage.py check --deploy runs the full set against production standards in any environment. The checks, their ids and their fixes are in Configuration checks.