小编典典

Flask和uWSGI-无法加载应用0(mountpoint ='')(找不到可调用的对象或导入错误)

flask

尝试使用uWSGI启动Flask时出现以下错误。这是我的开始方式:

>  # cd ..
>     root@localhost:# uwsgi --socket 127.0.0.1:6000 --file /path/to/folder/run.py --callable app -  -processes 2

这是我的目录结构:

-/path/to/folder/run.py
      -|app
          -|__init__.py
          -|views.py
          -|templates
          -|static

内容 /path/to/folder/run.py

if __name__ == '__main__':
   from app import app
   #app.run(debug = True)
   app.run()

内容 /path/to/folder/app/__init__.py

import os
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.login import LoginManager
#from flaskext.babel import Babel
from config import basedir
app = Flask(__name__)
app.config.from_object('config')
#app.config.from_pyfile('babel.cfg')

db = SQLAlchemy(app)
login_manager = LoginManager()
login_manager.setup_app(app)
login_manager.login_view = 'login'
login_manager.login_message = u"Please log in to access this page."

from app import views

*** Operational MODE: preforking ***
unable to find "application" callable in file /path/to/folder/run.py
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (pid: 26972, cores: 1)
spawned uWSGI worker 2 (pid: 26973, cores: 1)

阅读 1544

收藏
2020-04-05

共1个答案

小编典典

我的flask应用程序位于名为的变量中,因此我无法接受该解决方案app。你可以通过将以下内容放入你的wsgi中来解决此问题:

from module_with_your_flask_app import app as application

因此,问题很简单,uwsgi需要一个名为的变量application

2020-04-05