Pass command line parameters to uwsgi script

Krzysztof Rosiński picture Krzysztof Rosiński · Feb 10, 2014 · Viewed 10.5k times · Source

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]

And run:

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

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)

Answer

roberto picture roberto · Feb 11, 2014

python args:

--pyargv "foo bar"

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

uwsgi options:

--set foo=bar

uwsgi.opt['foo']
'bar'