Thanks for the help. I got your examples working. Am I correct that
pyargv cannot be set in the ini file itself? The following doesn't work,
for example:

app.ini
-------------------------------
[uwsgi]
http = 127.0.0.1:5000
wsgi-file = app.py
callable = app
pyargv = "--important_parameter hello"
-------------------------------

even though the following does work:

        $ uwsgi --http 127.0.0.1:5000 --wsgi-file app.py --callable app
--pyargv "--important_parameter hello"

(I've also tried the other "obvious" incarnations.)

Though I'm starting to think that your second recommendation is the
easiest. In that case if "import uwsgi" throws an exception, I can call
argparse and if it does not, I can get the options out of the wsgi-file.
That does seem like it'll be cleanest.

Thanks for the help!

Cheers,
Thomas

On 09/06/2015 04:37 PM, Roberto De Ioris wrote:
> 
>> I would like to pass command-line parameters to a wsgi script. Here's an
>> example:
>>
>> app.py
>> -------------------------------
>> import argparse
>>
>> from flask import Flask
>>
>> parser = argparse.ArgumentParser()
>>
>> parser.add_argument(
>>      "--important_parameter",
>>      required=False,
>>      type=str,
>>      default='127.0.0.1')
>>
>> args = parser.parse_args()
>>
>> important_parameter = args.important_parameter
>>
>> app = Flask(__name__)
>>
>> @app.route('/')
>> def index():
>>      return "index"
>>
>> if __name__ == '__main__':
>>      app.run()
>> -------------------------------
>>
>> I can pass parameters to it by running
>>
>>      $ python app.py --important_parameter 15
>>
>> I can call this script using uwsgi with the following:
>>
>>      $ uwsgi --http 127.0.0.1:5000 --wsgi-file app.py --callable app
>>
>> Or with the following wsgi-file:
>>
>> app.ini
>> -------------------------------
>> [uwsgi]
>> http = 127.0.0.1:5000
>> wsgi-file = app.py
>> callable = app
>> -------------------------------
>>
>> Does uwsgi allow passing in that important_parameter somehow? I've
>> searched online and found very terse solutions I didn't understand and
>> couldn't make work. I've also considered passing the information through
>> environment variables, but I would much prefer this method.
>>
>> Thank you very much for any help.
>>
>> Cheers,
>> Thomas
>> _______________________________________________
>> uWSGI mailing list
>> [email protected]
>> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>>
> 
> Hi, you can pass argument (the ones you read via sys.argv) with the
> --pyargv option.
> 
> Otherwise just add your option to the uWSGI config file, and access them
> with uwsgi.opt dictionary
> 
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to