-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
파이썬 설정로드, IDE선택 #1
Comments
|
1. 설정값을 어떻게 불러올까?
|
설정값은 pydantic패키지 BaseSettings모듈을 이용패키지 설치pip install pydantic python-dotenv env파일 생성
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" 설정값 로드
class FactoryConfig:
"""Returns a config instance depending on the ENV_STATE variable."""
def __init__(self, env_state: Optional[str]):
self.env_state = env_state
def __call__(self):
if self.env_state == "dev":
return DevConfig()
elif self.env_state == "prod":
return ProdConfig()
elif self.env_state == "stage"
return StageConfig() 설정은 어떻게?
class GlobalConfig(BaseSettings):
"""Global configurations."""
# define global variables with the Field class
ENV_STATE: Optional[str] = Field(None, env="ENV_STATE")
# environment specific variables do not need the Field class
REDIS_HOST: Optional[str] = None
REDIS_PORT: Optional[int] = None
REDIS_PASS: Optional[str] = None
class Config:
"""Loads the dotenv file."""
env_file: str = ".env"
class DevConfig(GlobalConfig):
"""Development configurations."""
class Config:
env_prefix: str = "DEV_"
class ProdConfig(GlobalConfig):
"""Production configurations."""
class Config:
env_prefix: str = "PROD_" 참고자료 |
2. 어떤 에디터를 사용할까?
|
3. 어떻게 pycharm에서 실행할까?
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: