Build application made with Flask

Asked

Viewed 31 times

0

While running flash run, I get the following error:

Error: Detected Factory 'create_app' in module 'spcdados.app', but could not call it without Arguments. Use "FLASK_APP='spcdados.app:create_app(args)'" to specify Arguments.

My structure is this:

inserir a descrição da imagem aqui

My config files are as follows:

#app.py
from flask import Flask, abort, url_for, render_template
from spcdados.extensoes import configuration

def minimal_app(**config):
    app = Flask(__name__)
    configuration.init_app(app, **config)
    return app
    

def create_app(**config):
    app = minimal_app(**config)
    configuration.load_extensions(app)
    return app

#settings.toml
[default]
DEBUG = false
SQLALCHEMY_DATABASE_URI = 'sqlite:///development.db'
TITLE = "SPC DADOS"
SECRET_KEY = "Pocornio2233"
EXTENSIONS = [

    "spcdados.extensoes.appearence:init_app",
    "spcdados.extensoes.database:init_app",
    "spcdados.extensoes.auth:init_app",
    "spcdados.extensoes.admin:init_app",
    "spcdados.extensoes.commands:init_app",
    "spcdados.blueprints.views:init_app",
    "spcdados.blueprints.restapi:init_app"
]
#.env
FLASK_ENV = development 
FLASK_APP = spcdados.app:create_app

I cannot understand where else it is necessary to declare FLASK_APP, someone has already gone through it?

  • Where did you spin flask run? Tried to use FLASK_APP = app.py?

  • I went straight to the terminal of the visual code, and yes, flask_app is already set there because I am working with it in the structure of Blueprint and Factory

  • I found the bug, apparently it’s a bug that hasn’t been fixed with flask, I modified the app.py to not receive **config anymore and it worked =)

1 answer

0

This is a bug that has not yet been solved in flask, follows debate in git

Debate on the bug in question

So I modified my.py app that way

from flask import Flask
from spcdados.extensoes import configuration


def minimal_app():
    app = Flask(__name__)
    configuration.init_app(app)
    return app


def create_app():
    app = Flask(__name__)
    configuration.init_app(app)
    configuration.load_extensions(app)
    return app

Browser other questions tagged

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