FLASK_APP is unavailable when FlaskGroup is not used #5156
-
When cli group created with flask.cli.AppGroup and returned to cli instead of default flask.cli.FlaskGroup flask.cli.ScriptInfo failing to locate application with
Here is a simple example of executable file #!/usr/bin/env python
from os import environ
import click
from flask import Flask
from flask.cli import AppGroup
cli = AppGroup("main")
@cli.command()
def test():
click.echo("Test command")
def create_app() -> Flask:
app = Flask(__name__)
app.cli.add_command(cli)
return app
if __name__ == "__main__":
environ.setdefault("FLASK_APP", "main:create_app")
cli() If run this file with flask<2.2.0:
And with flask>=2.2.0:
I don't want to expand flask commands, so I don't use FlaskGroup, and use main.py script instead. This worked fine before 2.2.0. I think this error is caused by this commit. Before 2.2.0 ScriptInfo locates Environment:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You still need to run commands with the
If you really want to use only your group and not the if __name__ == "__main__":
info = ScriptInfo(create_app=create_app)
cli(obj=info) |
Beta Was this translation helpful? Give feedback.
You still need to run commands with the
flask
command, that's why you register them withapp.cli.add_command
.If you really want to use only your group and not the
flask
command, then you need to create theScriptInfo
object likeFlaskGroup
would have done for you.