Load config file which is located outside package directory #5429
-
I have a simple flask project as shown below. There is a config file
In the import json
from flask import Flask
def create_app():
app = Flask(__name__)
app.config.from_file("config.json", load=json.load)
@app.route("/hello")
def hello():
return "Hello, World!"
return app The configuration file {
"PORT": 5040,
"DEBUG": true
} When I run |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
The simplest answer is: use an absolute path. Relative paths are relative to the app config object's root path, which by default will be |
Beta Was this translation helpful? Give feedback.
The simplest answer is: use an absolute path.
Relative paths are relative to the app config object's root path, which by default will be
app.root_path
, which can be a couple of different things depending on how your package is configured. If you’re using asrc
layout, you might want to install your package in editable mode.