Right now, I start my web app like this:
$ gunicorn webapp:application
I want to feed some parameters to the application function inside my webapp.py. In particular, I want to use a config file to adjust how my webapp works.
I read the docs for how to configure gunicorn with a config file, but I don't want that.
I tried this and got an error:
$ gunicorn webapp:application dev.cfg
As far as I can tell, gunicorn tried to find a callable named named "application dev.cfg".
Any ideas?
In your application module you can do something like this:
def load_app(cfg_file):
cfg = load_app_config(cfg_file)
return my_app(cfg)
And then you start your app like such:
$ gunicorn 'webapp:load_app("/path/to/my_config.ini")'
answered.
@benoitc it's been several years, can you tell me if this answer is still correct? I've not been able to get this approach to work for me.
@pellunutty I don't think the answer is correct now. You can subclass one of the application classes (e.g. BaseApplication
) and parse relevant information in load_config
method. See http://docs.gunicorn.org/en/stable/custom.html for an example.
Most helpful comment
In your application module you can do something like this:
And then you start your app like such: