Gunicorn:尝试启动烧瓶服务器时,无法在“ wsgi”中找到属性“ app”

时间:2020-07-08 16:17:24

标签: python flask gunicorn

Gunicorn无法启动烧瓶服务器,并显示错误:Failed to find attribute 'app' in 'wsgi'.

wsgi.py

#!/usr/bin/python3
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/root/customer-account-automation/")

from app import app as application
if __name__ == "__main__":
    application.run()

app.py

#!/usr/bin/python3
from flask import Flask
app = Flask(__name__)
...

项目结构:

(customer-account-automation) root@jsd-user-management:~/customer-account-automation# tree
.
├── Pipfile
├── Pipfile.lock
├── README.md
├── __pycache__
│   ├── app.cpython-37.pyc
│   └── wsgi.cpython-37.pyc
├── app.py
├── customerAccountMgmt.py
├── get-pip.py
├── static
│   ├── app.js
│   ├── bulma.min.css
│   ├── highlight.min.css
│   ├── highlight.min.js
│   └── styles.css
├── templates
│   ├── 404.html
│   ├── base.html
│   ├── change_password.html
│   ├── create_user.html
│   ├── deactivate_user.html
│   └── login.html
└── wsgi.py

我检查了(Gunicorn can't find app when name changed from "application"),但它与我的无关,因为我已经使用了application

任何想法可能是什么问题?

1 个答案:

答案 0 :(得分:0)

Gunicorn正在wsgi中寻找应用,因此请更改

from app import app as application
if __name__ == "__main__":
    application.run()

from app import app as application
app = application

然后您可以运行do ...这就是我想您正在执行的

gunicorn <all the options here> wsgi:app
相关问题