app_config[config_name] getting KeyError null value for flask environment app_config[config_name] getting KeyError null value for flask environment flask flask

app_config[config_name] getting KeyError null value for flask environment


The first problem can be solved with a reasonable default:

config_name = os.getenv('FLASK_CONFIG') or 'default'

or just os.getenv('FLASK_CONFIG', 'default'), where the meaning of the default can be set in config.app_config

app_config = {    'development': DevelopmentConfig,    'production': ProductionConfig,    'default': ProductionConfig}

The app_config maps a name to an object with configuration. A reference ina string form is also allowed, but you can pass the object directly to .from_object):

app.config.from_object(app_config[config_name])

The configuration data stored e.g. DevelopmentConfig must contain the data items as its attributes. It can be a class.


For Linux first type:export FLASK_ENV=development