Reputation: 922
Trying to run a flask app in Gunicorn but I am getting the following error
Failed to find application object 'App' in 'run'
run.py
import app as flask_app
import os
if __name__ == "__main__":
App = flask_app.factory.create_app(celery=flask_app.celery)
App.run(debug=True, host='0.0.0.0')
Command to run the app using gunicorn
gunicorn --bind 0.0.0.0:5100 run:App
Could someone please tell me the possible cause and solution? If I've missed out anything, over- or under-emphasized a specific point, let me know in the comments.
I have also referred Error: gunicorn: Failed to find application object 'app' in 'app' but was not able to get a possible solution on changing the filename as mentioned in the answer
Upvotes: 1
Views: 1541
Reputation: 26329
App
needs to be on the top level scope:
import app as flask_app
import os
App = flask_app.factory.create_app(celery=flask_app.celery)
if __name__ == "__main__":
App.run(debug=True, host='0.0.0.0')
Upvotes: 2