时间:2021-07-01 10:21:17 帮助过:55人阅读
答案是Flask-Environments这个包。它能通过FLASK_ENV环境变量自动选择开发环境配置或生产环境配置。使用之前要先安装:
class Config(object):
DEBUG = True
BASEDIR = os.path.abspath(os.path.dirname(__file__))
HOST = '0.0.0.0'
PORT = '8000'
class Development(Config): # inherit from Config
pass
class Production(Config):
DEBUG = False
HOST = '127.0.0.1
PORT = 14000
app = Flask(__name__)
env = Environments(app)
env.from_object('config')