flask production and development mode flask production and development mode python python

flask production and development mode


One convention used is to specify an environment variable before starting your application.

For example

$ ENV=prod; python run.py

In your app, you check the value of that environment variable to determine which config to use. In your case:

run.py

import osif os.environ['ENV'] == 'prod':    config = ProductionConfig()else:    config = DevelopmentConfig()

It is also worth noting that the statement

print('THIS APP IS IN DEBUG MODE. YOU SHOULD NOT SEE THIS IN PRODUCTION.')

prints no matter which ENV you set since the interpreter executes all the code in the class definitions before running the rest of the script.


To add onto Daniel's answer:

Flask has a page in its documentation that discusses this very issue.

Since you've specified your configuration in classes, you would load your configuration with app.config.from_object('configmodule.ProductionConfig')