Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I pass an arg to the application that gunicorn runs? #135

Closed
mw44118 opened this issue Dec 9, 2010 · 5 comments
Closed

How do I pass an arg to the application that gunicorn runs? #135

mw44118 opened this issue Dec 9, 2010 · 5 comments

Comments

@mw44118
Copy link

mw44118 commented Dec 9, 2010

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?

@davisp
Copy link
Collaborator

davisp commented Dec 9, 2010

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")'

@benoitc
Copy link
Owner

benoitc commented Dec 12, 2010

answered.

@ghost
Copy link

ghost commented May 10, 2016

@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.

@berkerpeksag
Copy link
Collaborator

@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.

@gaecom
Copy link

gaecom commented Nov 24, 2023

please use the following codo to get arguments,then the error will be fixed
parser.parse_known_args()[0]

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants