代码:@app.cli.command() @click.option(‘–drop’, is_flag=True, help=‘Create after drop.’)
def initdb(drop):
“”“Initialize the database.”“”
if drop:
click.confirm(‘This operation will delete the database, do you want to continue?’, abort=True)
db.drop_all()
click.echo(‘Drop tables.’)
db.create_all()
click.echo(‘Initialized database.’)`
C:\Users\Administrator\PycharmProjects\hi>flask --help
Traceback (most recent call last):
File “c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\flask\cli.py”, line 529, in list_commands
rv.update(info.load_app().cli.list_commands(ctx))
File “c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\flask\cli.py”, line 384, in load_app
'Could not locate a Flask application. You did not provide ’
flask.cli.NoAppException: Could not locate a Flask application. You did not provide the “FLASK_APP” environment variable, and a “wsgi.py” or “app.py” module was not found in the current
directory.
Usage: flask [OPTIONS] COMMAND [ARGS]…
A general utility script for Flask applications.
Provides commands from Flask, extensions, and the application. Loads the
application defined in the FLASK_APP environment variable, or from a
wsgi.py file. Setting the FLASK_ENV environment variable to ‘development’
will enable debug mode.
> set FLASK_APP=hello.py
> set FLASK_ENV=development
> flask run
Options:
–version Show the flask version
–help Show this message and exit.
Commands:
db Perform database migrations.
routes Show the routes for the app.
run Runs a development server.
shell Runs a shell in the app context.