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)
You could use an .ini file with the
pyargv
setting that @roberto mentioned. Let's call our config fileuwsgi.ini
and use the content:Then let's create a WGSI app to test it:
You can see how to load this file https://uwsgi-docs.readthedocs.io/en/latest/Configuration.html#loading-configuration-files:
Then when we
curl
the app, we can see our param echoed back:If you are trying to pass argparse style arguments to your WSGI app, they work just fine in the
.ini
too:python args:
--pyargv "foo bar"
uwsgi options:
--set foo=bar
I ended up using an env variable but setting it inside a start script: