gpt4 book ai didi

uWSGI 根据环境变量设置配置

转载 作者:行者123 更新时间:2023-12-01 01:48:01 27 4
gpt4 key购买 nike

请帮助我理解 uWSGI 配置逻辑。
我有一个环境变量 ENVIRONMENT .假设它的值可以是 devprod .我想根据 ENVIRONMENT 的值设置配置选项

# always executes print statement, doesn't matter what ENVIRONMENT is set to
if-env= ENVIRONMENT
if-opt: %(_)=dev
print = RUNNING %(_)
endif:
endif =

# always executes print statement, doesn't matter what ENVIRONMENT is set to
running = ENVIRONMENT
if-opt: running=dev
print = RUNNING %(_)
endif:

我会假设如果 ENVIRONMENT设置为 prod没有任何作业或 print内部声明 if-opt块将执行。但事实并非如此。

最佳答案

这应该有效:

[uwsgi]
if-env = ENVIRONMENT
env = %(_)
endif =
if-not-env = ENVIRONMENT
env = none
endif =
print = RUNNING %(env)
if-opt = env=dev
print = running dev yay
endif =

您在 INI 配置中使用了 YAML 语法。我也不得不带 if-optif-env因为它在提示递归。可能有办法让它更短,但这是有效的。

关于uWSGI 根据环境变量设置配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47091122/

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