The docs say Both methods have the exact same effect. , but they refer to the fact that the Flask application is actually running.
http://flask.pocoo.org/docs/quickstart/#debug-mode
In the case described above, the best option would be to use the first method, since you check the value of app.debug before starting the application, but after determining it and after installing app.debug .
With this in mind, as your application gets larger, you might consider creating a slightly more robust structure in which you can define the config-$ENV.py with the debug flag set in it.
application / CONF / config -dev.py
DEBUG = True # ... other settings (eg, log location, project root, etc)
application / CONF / config -live.py
DEBUG = False # ... other settings (eg, log location, project root, etc)
app / CONF / __ __ INIT. RU
EMPTY FILE
app / __ __ INIT. RU
from flask import Flask def create_app(env='dev'): app = Flask(__name__) app.config.from_object('app.conf.config-%s' % env) if app.debug: print 'running in debug mode' else: print 'NOT running in debug mode' return app
This means that you can immediately check whether your application will be running in debug mode, and when you start the application, you can indicate in which environment it is running, which will determine whether the debug setting is set to True or False "
run.py
from app import create_app import os port = int(os.environ.get('PORT', 5000)) app = create_app(env='dev')