Gunicorn can't find app when name changed from “application”

半城伤御伤魂 提交于 2019-11-30 04:21:23

Gunicorn (and most WSGI servers) defaults to looking for the callable named application or app in whatever module you point it at. Simply adding an alias from myproject import myapp as application or application = myapp will let Gunicorn discover the callable again.

However, the wsgi.py file or the alias aren't needed, Gunicorn can be pointed directly at the real module and callable, and can even call an app factory with arguments. A separate wsgi.py file is not required in most cases.

gunicorn myproject:myapp --workers 16
# equivalent to "from myproject import myapp as application"

gunicorn 'myproject.app:create_app("production")' --workers 16
# equivalent to:
# from myproject.app import create_app
# application = create_app("production")

Gunicorn imports the name after the ":" from the path before it. If there are parentheses, the name is called with arguments to get the application. If not, the name is assumed to be the application.

If you're trying to serve an app with variable name app within server/cats.py, you can start the server on port 8000 as follows:

gunicorn server.cats:app -b 0.0.0.0:8000
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!