Reputation: 2325
I am trying to run a Flask app on Heroku (with nginx + gunicorn). My Heroku procfile is:
web: bin/start-nginx gunicorn -c config/gunicorn.py myflaskmodule:app
I keep getting errors from gunicorn such as:
gunicorn.errors.HaltServer: <HaltServer 'App failed to load.' 4>
or, depending on the app name I have tried, the gunicorn error can be:
Application object must be callable.
The Flask app is set up within a directory named myflaskmodule
, containing a static
directory, templates
directory, auth.py
, db.py
, btac.py
, and __init__.py
.
In btac.py
a blueprint is defined as:
bp = Blueprint('btac', __name__, url_prefix='/btac')
Then I define several flask functions in btac.py
such as:
@bp.route('/', methods=['GET'])
def index():
# Do some things...
return render_template()
In __init.py__
I have one function:
def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)
# lots of other unrelated content here...
db.init_app(app)
app.register_blueprint(auth.bp)
app.register_blueprint(btac.bp)
return app
In the terminal (or a bash script), after executing export FLASK_ENV=development
and export FLASK_APP=myflaskmodule
, the Flask app runs locally with flask run
.
How do I define the last argument in the Heroku procfile? It should be module_name:app_name
. I have tried myflaskmodule:app
, myflaskmodule:myflaskmodule
, myflaskmodule:bp
, myflaskmodule:btac
.
I am fairly confident the first part of the argument should be myflaskmodule
(the name of the main Flask directory), but I can't seem to correctly define the name of the Flask app.
Flask==1.0.2, gunicorn==19.9.0
Upvotes: 2
Views: 1300
Reputation: 331
If you put web: gunicorn "myflaskmodule:create_app()"
in your Procfile that should work. In the code above you don't have an app variable to use with myflaskmodule:app
, but you do have a function that returns a Flask app, so you can use that.
Upvotes: 3