Search code examples
flaskwsgi

Flask instance name must be 'application', anything else, like 'app' will fail


I have been working on configuring my Flask web application to run on an Ubuntu machine, to move away from the framework's development server to a production server.

To help me configure WSGI and nginx, I followed this guide posted from DigitalOcean

Following the guide, everything works great! Note however in this example, the instance of Flask is named 'application', a bit different than the 'app' that is commonly used almost everywhere (such as on the Flask website and documentation).

Contents of myflaskapp.py:

from flask import Flask
application = Flask(__name__)

@application.route("/")
def hello():
    return "Hello World!"

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

Contents of wsgi.py:

from weather import application

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

However, if I were to change the instance names in the above files from 'application' to 'app' I receive an 'Internal Server Error' with nothing in the log file indicating a reason why.

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

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

and

from myflaskapp import app

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

According to the comments in the tutorial posted above, a couple of other users were experiencing the same issues. I can't understand why this particular server requires the name to be 'application' - it's something I can live with, but it just seems odd.

Thanks for any ideas you might be able to provide!


Solution

  • Assuming that you mean uWSGI, it looks for something named application. If you'd like to give it a different name, you can specify one in your config:

    [uwsgi]
    callable = app