Flask-Migrate in Factory Standard - App error not found

Asked

Viewed 42 times

1

Hello,

I’m trying to run the remote: flask db init, but the traceback returns:

traceback:

main/app/Extensions/migrate.py:

from flask_migrate import Migrate
from main.extensions.sqlalchemy import db

migrate = Migrate()


def init_app(app):
    migrate.init_app(app, db)

main/app/Extensions/dynaconf.py:

from importlib import import_module
from dynaconf import FlaskDynaconf


def load_extensions(app):
    for extension in app.config.get('EXTENSIONS'):
        module = import_module(extension)
        module.init_app(app)


def init_app(app):
    FlaskDynaconf(app)

main/app/app.py:

from flask import Flask
from main.extensions import dynaconf

_SECRET_KEY = None


def create_app():
    app = Flask(__name__)
    dynaconf.init_app(app)
    dynaconf.load_extensions(app)
    _SECRET_KEY = app.config.get('SECRET_KEY')

    return app

1 answer

0

You’re forgetting to import the app in the files "main/app/Extensions/migrate.py" and "main/app/Extensions/dynaconf.py"

in the first line of both you put

from app import app
  • Does not scroll, if I do this will scroll Circular Import and run to. The load_extensions function initializes all modules within app.

  • you are also programming in the style that the object oriented only that in structured language, flask is object oriented, can use the creation of classes to have resources as constructor, which you did in init_app

Browser other questions tagged

You are not signed in. Login or sign up in order to post.