How to get config params in another module in flask python? How to get config params in another module in flask python? flask flask

How to get config params in another module in flask python?


Your structure is not really clear but by what I can get, import your configuration object and just pass it to app.config.from_object():

from flask import Flaskfrom <path_to_config_module>.config import DevelopmentConfigapp = Flask('Project')app.config.from_object(DevelopmentConfig)if __name__ == "__main__":    application.run(host="0.0.0.0")

if your your config module is in the same directory where your application module is, you can just use :

from .config import DevelopmentConfig


The solution was to put app initialization in another file (e.g: myapp_init_file.py) in the root:

from flask import Flaskapp = Flask(__name__)# Change this on production environment to: config.ProductionConfigapp.config.from_object('config.DevelopmentConfig')

Now to access config parameters I just need to import this module in different files:

from myapp_init_file import app

Now I have access to my config parameters as below:

app.config['url']

The problem was that I had an import loop an could not run my python app. With this solution everything works like a charm. ;-)