gpt4 book ai didi

python - 如何获取所有可用的命令选项来设置环境变量?

转载 作者:行者123 更新时间:2023-12-03 20:30:06 25 4
gpt4 key购买 nike

flask manual about Setting Command Options只讲命令FLASK_RUN_PORT设置可以通过 Click 加载的环境变量。

我如何找到其他选项并将它们与模式一起使用 FLASK_COMMAND_OPTION ?

我想将它设置为我的 vscode launch.json。

最佳答案

您可以通过在 shell 中执行来访问所有可用命令:

flask --help

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


然后,如果您想列出给定命令的所有可用选项,例如 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.


因此,您可以将它们与文档示例中的模式一起使用,您只需在 ALLCAPS 中用下划线连接名称和选项:
export FLASK_RUN_PORT=8000
export FLASK_RUN_HOST=0.0.0.0

您还可以定义 bool 选项:
export FLASK_RUN_RELOAD=True   
export FLASK_RUN_RELOAD=False

注意: flask --help将列出默认命令,但如果您在执行此帮助 ( export FLASK_APP=my_app.py ) 之前定义您的应用程序,您还将获得所有自定义命令。

Commands:
db Perform database migrations.
deploy
run Runs a development server.
shell Runs a shell in the app context.
test perform tests

关于python - 如何获取所有可用的命令选项来设置环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50389273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com