-1

I have flask application which uses application factory pattern to instantiate flask application. I am trying to integrate Flask CLI command line to my flask app.

Can any one help me in understanding the use of create_app parameter inside FlaskGroup call.

Following is my code snippet.

from project import create_app, db
from flask.cli import FlaskGroup
app = create_app()
cli = FlaskGroup(create_app=create_app)

If i had used like normal flask application, then i would n't have to use create_app parameter, in which case my code snippet looks like

from project import app, db
from flask.cli import FlaskGroup
cli = FlaskGroup(app)
Derlin
  • 9,572
  • 2
  • 32
  • 53
madhu sudhan
  • 177
  • 1
  • 14

1 Answers1

-1

Upgrade to Flask 1.0. The flask command now understands how to work with factory functions.

FLASK_APP=myapp
flask run

Flask will import myapp, find the create_app function, and call it to get an app object. See the docs for more info.


Assuming you actually want a custom cli object (you most likely don't), then you're using it correctly. You pass the factory function to the group and it will call it when it needs the app object.

davidism
  • 121,510
  • 29
  • 395
  • 339