You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ENV_STATE="dev"# or prod
DEV_REDIS_HOST="127.0.0.1"
DEV_REDIS_PORT="4000"
PROD_REDIS_HOST="127.0.0.2"
PROD_REDIS_PORT="5000"
설정값 로드
.env파일에서 env_state값으로 런타임모드 확인
classFactoryConfig:
"""Returns a config instance depending on the ENV_STATE variable."""def__init__(self, env_state: Optional[str]):
self.env_state=env_statedef__call__(self):
ifself.env_state=="dev":
returnDevConfig()
elifself.env_state=="prod":
returnProdConfig()
elifself.env_state=="stage"returnStageConfig()
설정은 어떻게?
공통으로 사용하는 변수는 GlobalConfig에 설정
각 런타임모드는 Globalconfig를 상속해서 구현하고, env_prefix를 사용해서 설정 값 로드
classGlobalConfig(BaseSettings):
"""Global configurations."""# define global variables with the Field classENV_STATE: Optional[str] =Field(None, env="ENV_STATE")
# environment specific variables do not need the Field classREDIS_HOST: Optional[str] =NoneREDIS_PORT: Optional[int] =NoneREDIS_PASS: Optional[str] =NoneclassConfig:
"""Loads the dotenv file."""env_file: str=".env"classDevConfig(GlobalConfig):
"""Development configurations."""classConfig:
env_prefix: str="DEV_"classProdConfig(GlobalConfig):
"""Production configurations."""classConfig:
env_prefix: str="PROD_"
Activity
choisungwook commentedon Apr 27, 2022
choisungwook commentedon Apr 27, 2022
1. 설정값을 어떻게 불러올까?
choisungwook commentedon Apr 27, 2022
설정값은 pydantic패키지 BaseSettings모듈을 이용
패키지 설치
env파일 생성
설정값 로드
설정은 어떻게?
참고자료
choisungwook commentedon Apr 27, 2022
2. 어떤 에디터를 사용할까?
choisungwook commentedon Apr 27, 2022
3. 어떻게 pycharm에서 실행할까?
설정로드 추가 #1
[-][백엔드] 파이썬 프로젝트 구조 설정[/-][+]파이썬 설정로드, IDE선택[/+]