Flask and uWSGI - unable to load app 0 (mountpoint='') (callable not found or import error)(

Posted 功夫 熊猫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flask and uWSGI - unable to load app 0 (mountpoint='') (callable not found or import error)(相关的知识,希望对你有一定的参考价值。

Here is my directory structure:

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

Contents of /path/to/folder/run.py

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

Contents of /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)
shareimprove this question
 

2 Answers

uWSGI doesn‘t load your app as __main__, so it never will find the app (since that only gets loaded when the app is run as name __main__). Thus, you need to import it outside of the if __name__ == "__main__": block.

Really simple change:

from app import app

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

Now you can run the app directly with python run.py or run it through uWSGI the way you have i

以上是关于Flask and uWSGI - unable to load app 0 (mountpoint='') (callable not found or import error)(的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu18部署uwsgi+flask应用

flask使用工厂函数后怎么用uwsgi启动?

如何使用 Flask+uWSGI 设置自动重载?

flask项目下的uwsgi配置方式及示例

flask uwsgi nginx

uwsgi + nginx + flask:上游过早关闭