Flask manufacturing and development
I have developed a flask application and I want to publish it for production, but I do not know how to make the separation between production and development environment (database and code), you have docs to help me or the code, I specify in the config file .py are two environments, but I don't know how.
class DevelopmentConfig(Config):
"""
Development configurations
"""
DEBUG = True
SQLALCHEMY_ECHO = True
ASSETS_DEBUG = True
DATABASE = 'teamprojet_db'
print('THIS APP IS IN DEBUG MODE. YOU SHOULD NOT SEE THIS IN PRODUCTION.')
class ProductionConfig(Config):
"""
Production configurations
"""
DEBUG = False
DATABASE = 'teamprojet_prod_db'
source to share
One of the rules used is to specify an environment variable before starting the application.
for example
$ ENV=prod; python run.py
In your application, you check the value of this environment variable to determine which configuration to use. In your case:
run.py
import os
if 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 one ENV
you install as the interpreter executes all the code in the class definitions before running the rest of the script.
source to share
To add Daniel's answers:
The checkbox contains a page in its documentation that addresses this issue.
Since you have specified your config in the classes, you must load your config with app.config.from_object('configmodule.ProductionConfig')
source to share