Unable to load instance config in app organized as a package

Viewed 1545

In __init__.py I'm trying to load the config from a Python file relative to the instance folder. That's throwing an error Unable to load configuration file (No such file or directory): '/home/ais-flask/ais/instance/config.py', which is wrong, because the instance folder should be next to the package, not in it, and mine is. I install my package in develop mode with setup.py develop. I run the app with python __init__.py. Why isn't this working?

ais-flask/
    ais/
        __init__.py
    instance/
        config.py
    setup.py
from flask import Flask

app = Flask(__name__, instance_relative_config=True)
app.config.from_pyfile('config.py')
2 Answers
import os
from flask import Flask


app = Flask(__name__, instance_path=os.path.join(os.path.abspath(os.curdir), 'instance'), instance_relative_config=True)
app.config.from_object('config')
app.config.from_pyfile('config.cfg')


@app.route('/')
def hello_world():
    return 'Hello, World!'
Related