pythonflaskconfigpython-3.11toml

Is there a reason that some keys and values will not load in TOML? (Python config import)


I've set up my flask app to read my config file...

app.config.from_file("../CONFIGS/config.py", lambda f: tomllib.load(f.buffer))
f.write(str(app.config))

when I go to see the output some of the line from the config are there...

MY_VARIABLE = "1"

but

my_variable = "1"

is missing from the output...

Am I missing something?

using the 3.11 built in TOMLLIB with python 3.11


Solution

  • In Flask, the app configuration system only picks up keys that are in uppercase, so any lowercase settings from your config file get ignored. That's why you're seeing "MY_VARIABLE" but not "my_variable".

    Change your config file so that all the setting names are uppercase, like MY_VARIABLE. (or) Or, if you need to keep lowercase names, you can load the file yourself and manually add each setting to app.config in uppercase form.