Here is my project structure:
project/
src/
settings.py
examples/
example-config.yaml
# settings.py
OUTPUT_DIR = "generated"
# example-config.yaml
OUTPUT_DIR: "custom_dir"
According to the docs settings.py
gets automatically loaded. Therefore the code below works:
from dynaconf import settings
print(settings.OUTPUT_DIR) # prints -> generated
However when trying to load the example-config.yaml
, nothing changes. See below:
from dynaconf import settings
settings.load_file("../examples/example-config.yaml")
print(settings.OUTPUT_DIR) # prints -> generated. expected -> custom_dir
Am I missing something here?
You should explicitly set the root directory for the import, I was facing a similar problem where the configuration file was not found, and dynaconf silently suppressed all errors.
For older Dynaconf you can set the ROOT_PATH_FOR_DYNACONF
environment variable to the base path of the project.
For Dynaconf version > 3, the recommendation is to make an instance of Dynaconf yourself. You should set the root_path
there.
config.py file:
from dynaconf import Dynaconf
settings = Dynaconf(root_path="/path/to/project")
Then you can use the relative import.
from project.config import settings
settings.load_file("examples/example-config.yaml")