Skip to content

Instantly share code, notes, and snippets.

@lpe234
Created July 26, 2017 01:44
Show Gist options
  • Save lpe234/bbded4d237fb7523ed9a3350c04c6346 to your computer and use it in GitHub Desktop.
Save lpe234/bbded4d237fb7523ed9a3350c04c6346 to your computer and use it in GitHub Desktop.
flask config file
# -*- coding: UTF-8 -*-
__author__ = 'lpe234'
"""
config module
"""
class Config(object):
"""
basic config
"""
CONFIG_NAME = None
DEBUG = False
# mongo
MONGO_HOST = 'localhost'
MONGO_PORT = 27017
MONGO_DBNAME = 'lemon'
class ProductConfig(Config):
"""
product config
"""
pass
class DevelopConfig(Config):
"""
develop config
"""
pass
class Lupengdemacbookpro_localConfig(DevelopConfig):
"""
self config
"""
CONFIG_NAME = 'LupengConfig'
DEBUG = True
pass
class BogonConfig(Lupengdemacbookpro_localConfig):
"""
Bogon Fix
"""
pass
@lpe234
Copy link
Author

lpe234 commented Jul 26, 2017

# load config by hostname, and check config.
host_name = socket.gethostname().capitalize().replace('.', '_').replace('-', '')
lemon_app.config.from_object(getattr(settings, '{}Config'.format(host_name), settings.Config))
if lemon_app.config.get('CONFIG_NAME'):
    info_msg = 'load config from: {}'.format(lemon_app.config.get('CONFIG_NAME'))
    lemon_app.logger.info(info_msg)
else:
    err_msg = 'Config Wrong, Please Check With host_name: {}'.format(host_name)
    exit(err_msg)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment