Python ????????ù???
?????keakon?????? ???????[ 2016/10/24 11:27:24 ] ????????Python ???ù???
??????ο??????μ? Python ??????????????????????????????????????????????????????п??????????????????????
???????????????????????????????????????????????????????????÷?????????????????????????????
??????????????????Щ??????
????1??????????????????
????????????????????????????????????????????????????????????????????????????
????2?????????????????
??????????????????У???????????С?????????????????ò??????????壬????????????????
????3??????????????/??顣
????????????????????????????????????????????????????????ú??а?????
????4???????????? Python ????
?????????????н????????????鷳?????????????????????????????????飩????????????????????????????????????????·??????
????5???????????????е????????????????
????????????У?????????????????????????????е????á??????????????????????????????塣
???????????????????????????????????????
????1?????????????д????????????????????????????????????????????????????·????
????2????÷????????÷?????????????á?
???????????????????鷳??????????????????????????????滻????????????????????????????????????????????????????????????????????????????????á??????????????????????????????????????
????????????????? Python ???????粻????????????????????棬??????÷????????????????????÷????????????????????????÷????????????????????????????????????÷????????????????????????????????
????????????????????????? Python ???????ζ???? Python ?????????????????????? Python ??????У????????????????
?????????????? Config ???????????????????????????
# config/default.py
class Config(object):
DEBUG_MODE = True
PORT = 12345
COOKIE_SECRET = 'default'
REDIS_CONFIG = {'host': 'localhost'?? 'port': 6379?? 'db': 0}
# ...
# config/development.py
from .default import Config
class DevelopmentConfig(Config):
COOKIE_SECRET = 'dev'
# config/unit_testing.py
from .default import Config
class UnitTestingConfig(Config):
REDIS_CONFIG = {'host': 'localhost'?? 'port': 6379?? 'db': 1}
# config/production.py
from .default import Config
class ProductionConfig(Config):
COOKIE_SECRET = '...'
REDIS_CONFIG = {'unix_socket_path': '/tmp/redis.sock'}
?????????????????????????????Ч?????????????????
# config/__init__.py
import logging
import os
env = os.getenv('ENV') # ??????????????????????????
try:
if env == 'PRODUCTION':
from .production import ProductionConfig as CONFIG
logging.info('Production config loaded.')
elif env == 'TESTING':
from .testing import TestingConfig as CONFIG
logging.info('Testing config loaded.')
elif env == 'UNIT_TESTING':
from .unit_testing import UnitTestingConfig as CONFIG
logging.info('Unit testing config loaded.')
else: # ?????????????????????????????????????????
from .development import DevelopmentConfig as CONFIG
logging.info('Development config loaded.')
except ImportError:
logging.warning('Loading config for %s environment failed?? use default config instead.'?? env or 'unspecified')
from .default import Config as CONFIG
?????????????????????????ò??????????????ɡ???????? Supervisor ?????????????????? environment = ENV="PRODUCTION" ???ü??ɡ?
???????????????????????????????????????????????????
???????????????????????????????????????
????????????????? Python ?? package??????????????????????? package ?????
????????????????????????????????
??????????????????????????
# config/default.py
class Config(object):
ROOT_PATH = '/'
LOGIN_PATH = ROOT_PATH + 'login'
SCHEME = 'http'
DOMAIN = 'localhost'
ROOT_URL = '%s://%s%s' % (SCHEME?? DOMAIN?? ROOT_PATH)
# config/production.py
from .default import Config
class ProductionConfig(Config):
ROOT_PATH = '/blog/'
LOGIN_PATH = ROOT_PATH + 'login'
DOMAIN = 'www.keakon.net'
ROOT_URL = '%s://%s%s' % (Config.SCHEME?? DOMAIN?? ROOT_PATH)
???????У?LOGIN_PATH ?? LOGIN_URL ??????????????????????????????? ProductionConfig ????????????е???????
???????????Щ?????????????????????ó?????????????????
class _AfterMeta(type):
def __init__(cls?? name?? bases?? dct):
super(_AfterMeta?? cls).__init__(name?? bases?? dct)
cls._after()
class Config(object):
__metaclass__ = _AfterMeta
ROOT_PATH = '/'
SCHEME = 'http'
DOMAIN = 'localhost'
@classmethod
def _after(cls):
cls.LOGIN_PATH = cls.ROOT_PATH + 'login'
cls.ROOT_URL = '%s://%s%s' % (cls.SCHEME?? cls.DOMAIN?? cls.ROOT_PATH)
# config/production.py
from .default import Config
class ProductionConfig(Config):
ROOT_PATH = '/blog/'
DOMAIN = 'www.keakon.net'
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11