为什么我使用 Gunicorn 来 运行 Flask 应用程序似乎“没有名为应用程序的模块”

Why I use Gunicorn to run Flask app it seems ‘no module named app’

Flask 应用没问题,但是当我使用 Gunicorn 命令时:

gunicorn -w 4 -b 127.0.0.1:8004 app:app

gunicorn -w 4 -b 127.0.0.1:8004 route:app

似乎导入错误:没有名为 'app'

的模块

我的结构

app
    │  config.py
    │  data.db
    │  forms.py
    │  models.py
    │  mulu.txt
    │  route.py
    │  __init__.py
    │  templates
    |  static

app在init.py

中定义
from flask import Flask
app = Flask(__name__)

route.py

from app import app
@app.route('/')
def hello_world():
    return 'hello world'

if __name__ == '__main__':
    app.run()

为什么?谢谢!

您的应用程序实例在 __init__.py 中定义,因此您应该

gunicorn -w 4 -b 127.0.0.1:8004 __init__:app