请帮我理解uWSGI配置逻辑。
我有一个环境变量ENVIRONMENT
。我们可以说它的值可以是dev
或prod
。我想根据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
语句都不会执行。但事实并非如此。
答案 0 :(得分:3)
这应该有效:
[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-opt
中取出if-env
,因为它抱怨递归。可能有一种方法可以缩短它,但这很有效。