How to import from config file in Flask?

When people talk about configs in Flask, they are generally talking about loading values into the app’s configuration. In your above example you could have something like app.config.from_object('config') in your init.py file. Then all the configuration values will be loaded into the app.config dictionary.

Then in any of your files you could just import the app object to gain access to that dictionary. I tend to access that app object by doing from flask import current_app as app then just app.config['MY_SETTING'] to get the value I care about. Read up more in the documenation.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)