簡體   English   中英

嘗試通過 uwsg 運行 Flask 應用程序時無法從 uwsgi 加載配置

[英]unable to load configuration from uwsgi when attempting to run flask app via uwsg

我有以下 uwsgi app.ini 文件:

[uwsgi]
wsgi-file = wsgi.py
callable = app
socket = :5000
processes = 5
threads = 2
master = true
chmod-socket = 660
vacuum = true
die-on-term = true

wsgi.py 內容:

from app import start

start()

最后是 app.py,它是 Flask 應用程序本身(很長,所以我只會放相關的):

# instantiate the app
app = Flask(__name__, static_url_path='', static_folder='static', template_folder='templates')
app.config.from_object(__name__)

# enable CORS
CORS(app, resources={r'/*': {'origins': '*'}})


@app.route('/')
def index():
    return render_template('index.html')


... all sort of methods here ...


def start():
    print("STARTING !!!")
    app.run(host='0.0.0.0')


if __name__ == '__main__':
    start()

所有文件都在同一個文件夾中。 當我運行uwsgi app.ini我得到這個:

 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
unable to load configuration from uwsgi

為什么是這樣?

謝謝你的幫助

快速瀏覽會發現兩個問題。 首先, uwsgiapp.run()不兼容。 當您使用 Flask 開發環境時,您將使用后者。 uwsgi需要保存 Flask 實例的對象。 按照慣例,這是app ,但您可以使用不同的名稱(並配置uwsgi以查找不同的名稱)。

這是第二個問題。 uwsgi加載wsgi.py (導致app.run()這是越來越您最什么,你看到的,然后它尋找app 。但是,因為你想導入app ,該appwsgi.py有ISN” t Flask 實例。

要做的簡單的事情是(在 uwsgi.ini 中)替換

file=wsgi.py

module=app:app

那應該繞過對start()的調用,讓uwsgi處理事情。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM