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
There was a mistake here db.init_app(app)
. I changed it to db.init_app(application) and it is working success now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With