Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FlaskApp has no attribute 'config'

all. I writing project using Flask, SQLAlchemy, and connexion. Before connexion was implemented, all works success (p.s. when app created as app = Flask(__name__). After implementing connexion raises an exception: 'SQLALCHEMY_DATABASE_URI' not in app.config and AttributeError: 'FlaskApp' object has no attribute 'config'. So where is a mistake? Help, please.

run.py:

from app import create_app
app = create_app('development')
if __name__ == '__main__':
    app.run()

app:

...
from settings import app_config
db = SQLAlchemy()
def create_app(config_name):
    # app = Flask(__name__)
    app = connexion.App(__name__)
    app.add_api('swagger.yml')
    application = app.app
    application.config.from_object(app_config[config_name])
    application.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
    return app

settings.py

class BaseConfig(object):
    DEBUG = False
    CSRF_ENABLED = True
    SECRET = os.getenv('SECRET', 'default_secret_key')
    DEFAULT_URI = 'postgresql://shooter:shooter@localhost/shooterstats'
    SQLALCHEMY_DATABASE_URI = DEFAULT_URI

class DevelopmentConfig(BaseConfig):
    DEBUG = True
like image 636
Oleksii Petrushynskyi Avatar asked Oct 16 '22 13:10

Oleksii Petrushynskyi


1 Answers

There was a mistake here db.init_app(app). I changed it to db.init_app(application) and it is working success now.

like image 84
Oleksii Petrushynskyi Avatar answered Oct 21 '22 08:10

Oleksii Petrushynskyi