5

The flask manual about Setting Command Options only talks about the command FLASK_RUN_PORT to set environment variables that can be loaded by Click.

How can i find the other options and use them with the pattern FLASK_COMMAND_OPTION ?

I want to set it to my vscode launch.json.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Kamil
  • 594
  • 1
  • 8
  • 28

1 Answers1

9

You can access all available commands by executing in a shell :

flask --help
[...]
Commands:
      db     Perform database migrations.
      run    Runs a development server.
      shell  Runs a shell in the app context.

Then if you want to list all available options for a given command like run:

flask run --help 
Options:
      -h, --host TEXT                 The interface to bind to.
      -p, --port INTEGER              The port to bind to.
      --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.
      --eager-loading / --lazy-loader
                                      Enable or disable eager loading.  By default
                                      eager loading is enabled if the reloader is
                                      disabled.
      --with-threads / --without-threads
                                      Enable or disable multithreading.
      --help                          Show this message and exit.

So you can use them with the pattern like in the doc examples, you just have to concatenate the name and the options with underscores, in ALLCAPS:

export FLASK_RUN_PORT=8000
export FLASK_RUN_HOST=0.0.0.0

You can also define boolean options :

export FLASK_RUN_RELOAD=True   
export FLASK_RUN_RELOAD=False

NOTE : flask --help will list default commands, but if you define your app before executing this help (export FLASK_APP=my_app.py), you will also get all custom commands.

Commands:
      db      Perform database migrations.
      deploy
      run     Runs a development server.
      shell   Runs a shell in the app context.
      test    perform tests
PRMoureu
  • 12,817
  • 6
  • 38
  • 48
  • Hi, is 'FLASK_RUN_HOST' a default commands? I just want to find other default commands. – Kamil May 18 '18 at 01:59
  • all commands appear at the end of the help documentation, you just have to concatenate the name and the options with underscores, in ALLCAPS. – PRMoureu May 18 '18 at 05:23
  • For flask run, your method works well. However, if I set the app.config['FLASK_RUN_PORT']=8000 in code and do flask run, then it still starts up on port 5000 – variable Nov 14 '19 at 07:19
  • @variable it's hard to debug this without context, could you create a question and define what you've tried exactly? – PRMoureu Nov 14 '19 at 16:58
  • I mean setting port via config variable does not work – variable Nov 14 '19 at 18:31
  • @variable See https://stackoverflow.com/questions/20212894/how-do-i-get-flask-to-run-on-port-80 – Polluks Feb 17 '21 at 12:57