Oleksii Petrushynskyi
Oleksii Petrushynskyi

Reputation: 373

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

Upvotes: 5

Views: 9844

Answers (2)

Zachary Chiodini
Zachary Chiodini

Reputation: 61

Here is one way you can set up your Flask application with Connexion.

import connexion

# This creates the connexion application instance.
connexion_app = connexion.App(__name__)
# This gets the underlying Flask app instance.
flask_app = connexion_app.app  # Flask(__name__)

🤠

Upvotes: 1

Oleksii Petrushynskyi
Oleksii Petrushynskyi

Reputation: 373

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

Upvotes: 3

Related Questions