Skip to content

flask命令

flask --help

shell
Usage: flask [OPTIONS] COMMAND [ARGS]...

  A general utility script for Flask applications.

  An application to load must be given with the '--app' option, 'FLASK_APP'
  environment variable, or with a 'wsgi.py' or 'app.py' file in the current
  directory.

Options:
  -e, --env-file FILE   Load environment variables from this file. python-
                        dotenv must be installed.
  -A, --app IMPORT      The Flask application or factory function to load, in
                        the form 'module:name'. Module can be a dotted import
                        or file path. Name is not required if it is 'app',
                        'application', 'create_app', or 'make_app', and can be
                        'name(args)' to pass arguments.
  --debug / --no-debug  Set debug mode.
  --version             Show the Flask version.
  --help                Show this message and exit.

Commands:
  routes  Show the routes for the app.
  run     Run a development server.
  shell   Run a shell in the app context.

flask run --help

shell
Usage: flask run [OPTIONS]

  Run a local development server.

  This server is for development purposes only. It does not provide the
  stability, security, or performance of production WSGI servers.

  The reloader and debugger are enabled by default with the '--debug' option.

Options:
  --debug / --no-debug            Set debug mode.
  -h, --host TEXT                 The interface to bind to.
  -p, --port INTEGER              The port to bind to.
  --cert PATH                     Specify a certificate file to use HTTPS.
  --key FILE                      The key file to use when specifying a
                                  certificate.
  --reload / --no-reload          Enable or disable the reloader. By default
                                  the reloader is active if debug is enabled.
  --debugger / --no-debugger      Enable or disable the debugger. By default
                                  the debugger is active if debug is enabled.
  --with-threads / --without-threads
                                  Enable or disable multithreading.
  --extra-files PATH              Extra files that trigger a reload on change.
                                  Multiple paths are separated by ':'.
  --exclude-patterns PATH         Files matching these fnmatch patterns will
                                  not trigger a reload on change. Multiple
                                  patterns are separated by ':'.
  --help                          Show this message and exit.

比如

shell
flask run --host=0.0.0.0 --port=9999

--reload、--no-reload、--debugger和--no-debugger参数对调试模式进行细致的设置。

调试模式下,关闭调试器,启用重载器

shell
export FLASK_APP=1hellowold.py
flask run --host=0.0.0.0 --port=9999 --debug --no-debugger

以上启动命令,并不会打印

 * Debugger is active!
 * Debugger PIN: xxxx

flask routes --help

shell
Usage: flask routes [OPTIONS]

  Show all registered routes with endpoints and methods.

Options:
  -s, --sort [endpoint|methods|domain|rule|match]
                                  Method to sort routes by. 'match' is the
                                  order that Flask will match routes when
                                  dispatching a request.
  --all-methods                   Show HEAD and OPTIONS methods.
  --help                          Show this message and exit.

flask shell --help

shell
Usage: flask shell [OPTIONS]

  Run an interactive Python shell in the context of a given Flask application.
  The application will populate the default namespace of this shell according
  to its configuration.

  This is useful for executing small snippets of management code without
  having to manually configure the application.

Options:
  --help  Show this message and exit.