将命令行参数传递给 uwsgi 脚本 [英] Pass command line parameters to uwsgi script

查看:56
本文介绍了将命令行参数传递给 uwsgi 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将参数传递给示例 wsgi 应用程序,:

I'm trying to pass arguments to an example wsgi application, :

config_file = sys.argv[1]

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World %s" % config_file]

然后运行:

uwsgi --http :9090 --wsgi-file test_uwsgi.py  -???? config_file # argument for wsgi script

有什么聪明的方法可以实现吗?在 uwsgi 文档中找不到它.也许还有另一种向 wsgi 应用程序提供一些参数的方法?(环境变量超出范围)

Any smart way I can achieve it? Couldn't find it in uwsgi docs. Maybe there is another way of providing some parameters to the wsgi application? (env. variables are out of scope)

推荐答案

python args:

python args:

--pyargv "foo bar"

--pyargv "foo bar"

sys.argv
['uwsgi', 'foo', 'bar']

uwsgi 选项:

--set foo=bar

--set foo=bar

uwsgi.opt['foo']
'bar'

这篇关于将命令行参数传递给 uwsgi 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆