Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deploying flask app with uwsgi and flask-script Manager

Traditionally, I have configured the UWSGI configuration file to call an application like below:

mydirectory/uwsgi_application.ini
...
#python module to import
app = run_web
module = %(app)
callable = app
...

,

mydirectory/run_web.py
from ersapp import app
if __name__ == "__main__":
    app.run()

,

mydirectory/ersapp/__init__.py
...
app = Flask('ersapp')
...

But now, I am following Miguel Grinberg's Flask book and here he uses an application factory like below

mydirectory/ersapp/__init__.py
...
def create_app(config_name):
    webapp = Flask(__name__)
    ...
    return webapp

with a "manager" (see flask-script Manager)

mydirectory/manage.py
from webapp import create_app
...
webapp = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(webapp)
...
if __name__ == '__main__':
    manager.run()

In this configuration, I trigger my development server with $ python manage.py runserver

whereas before I triggered it with $ python run_web.py

Now, I am struggling with what to put in the uwsgi configuration file to allow this app to be deployed via UWSGI. Specifically, the app, module, and callable variables.

The error I am getting in my logs is:

...
--- no python application found, check your startup logs for errors ---
...
like image 991
Brian Leach Avatar asked Jun 09 '15 00:06

Brian Leach


People also ask

Is Flask a uWSGI?

Flask is a WSGI application. A WSGI server is used to run the application, converting incoming HTTP requests to the standard WSGI environ, and converting outgoing WSGI responses to HTTP responses.


2 Answers

You don't use Flask-Script with uWSGI. You point it at the app directly. Or in your case, you point it at a call to the app factory. The simplest example is:

uwsgi --module 'myapp:create_app()'
like image 75
davidism Avatar answered Sep 25 '22 19:09

davidism


I am also using the flask-script manager , so what i did was

  • created a wsgi.py .which was like.

    from app import * application = create_app("development")

  • then uwsgi --wsgi-file wsgi.py --callable application

Note: the callable is the flask object name in the wsgi.py.

like image 21
GIRISH RAMNANI Avatar answered Sep 23 '22 19:09

GIRISH RAMNANI