반응형 분류 전체보기574 [Python] package name 에 하이픈(-)이 있을 때 import 하는 방법 가장 좋은 방법은 "-" 없이 package 를 생성하는거겠죠. (directory 나 filename 모두) 하지만, 어쩔수 없이 사용해야할 경우가 생긴다면, yourpath some-dir-name model.py class User 가 있다고 함 utils.py class Utils 가 있다고 함 이렇게 있을 때, module = __import__("yourpath.some-dir-name", fromlist=['model', 'utils']) User = module.model.User Utils = module.utils.Utils # 아래와 같이 import User 로 사용했을 때와 같이 사용 user: User = User() 2023. 9. 21. [FastAPI] SQLModel datetime column 기본값 현재시간 (UTC-한국기준) 아래와 같이 사용하면, 서버가 어디에 있든 UTC 기준 시간으로 입력됩니다. from typing import Optional from datetime import datetime from sqlmodel import Field, SQLModel, JSON, Column class User(SQLModel, table=True): __tablename__ = 'user' reg_date: Optional[datetime] = Field(default_factory=lambda: datetime.utcnow()) 한국시간으로 입력하려면, 아래와 같이 utc에 9시간을 더해주면됩니다. from datetime import datetime, timedelta reg_date: Optional[datetime].. 2023. 9. 19. [FastAPI] SQLModel 에서 MySQL 의 Json 컬럼 사용방법 sqlmodel 의 Field, SQLModel, JSON, Column 를 imort from sqlmodel import Field, SQLModel, JSON, Column friends_id_list 와 같이 python data type 은 dict SQLModel Field 는 sa_column=Column(JSON) 으로. class User(SQLModel, table=True): __tablename__ = 'user' user_id: str = Field(primary_key=True) friends_id_list: dict = Field(sa_column=Column(JSON)) reg_date: Optional[datetime] = Field(default_factory=dateti.. 2023. 9. 18. [AWS] "cannot import name 'DEFAULT_CIPHERS' from 'urllib3.util.ssl_'" on AWS Lambda using a layer lambda 에서 레이어를 추가하고 boto3 만 import 했는데 이런 오류가 발생하네요. botocore 가 아직은 urllib3 의 2.0 버전을 지원하지 않아서 발생하는 거더군요. 그래서 urllib3 버전이 2 미만이 되도록 설치 하면 됩니다. 또는 requests==2.28.2 로 설치, 저는 이 방법으로 간단하게 해결했습니다. 2023. 9. 16. [FastAPI] Html 띄우기 server.py from typing import Union from fastapi import FastAPI, Request from fastapi.templating import Jinja2Templates templates = Jinja2Templates(directory="templates") app = FastAPI() @app.get("/") def read_root(request: Request): return templates.TemplateResponse("test.html", {'request': request}) @app.get("/items/{item_id}") def read_item(item_id: int, q: Union[str, None] = None): return {"i.. 2023. 9. 15. [AWS] Cloud9 에서 Selenium 으로 크롤링하기 (Amazon Linux2) aws 에 접속해서 Cloud9 에서 새로운 환경 생성. 플랫폼은 Amazon Linux2 생성되면 환경으로 접속 후 터미널에서 아래 명령어 실행 chrome 설치 sudo yum update -y wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm sudo yum install -y ./google-chrome-stable_current_x86_64.rpm 링크 설정 sudo ln -s /usr/bin/google-chrome-stable /usr/bin/chromium 설치가 잘 되었다면 버전확인 했을 때 메시지가 나옴. 다음 명령어로 설치 여부 확인 터미널에서 google-chrome CLI 로 크롤링 동작 .. 2023. 9. 12. [vue] Composition api 에서 property로 받은 변수 watch 하는 방법 사용하려는 컴포넌트 vue 에서 다음과 같이 props를 사용하고 있을 때, import {useStore} from "vuex"; import {computed, watch} from "vue"; const store = useStore() const props = defineProps({ isDialogVisible: { type: Boolean, required: true, } }) // 생략 isDialogVisible 을 watch 하고 싶다면 watch(isDialogVisible, (newVal, oldVal) => {}) watch(props.isDialogVisible, (newVal, oldVal) => {}) 이 방법들은 안되고 아래와 같이 사용하면 됩니다. watch(()=>prop.. 2023. 9. 10. [Vue] computed 사용할 때 파라메터 넘기기 아래와 같이 사용하면 됩니다. Hello~ Bryan~ const alertColor = computed(()=>(num) =>{ ... 이 부분이 중요한거 같은데요. computed( (num) => { ... 로 사용하니 안되더라고요. 간단한 조건문 같은 경우는 굳이 computed 를 사용하지 않아도 될거같아요. Hello~ Bryan~ 저는 저 조건문의 변수가 상황에 따라 바뀌고, 경우의 수도 다양해서 computed 를 사용하려고 알아봤습니다. 2023. 9. 10. [tiangolo/SqlModel] where 절 사용하기 FastAPI 의 tiangolo 에서 사용하고 있는 SQLModel Where 사용법 간단히 알아보기 기본 사용 SELECT id, name, secret_name, age FROM hero WHERE age >= 35 이 쿼리는 다음과 같이 사용합니다. def select_heroes(): with Session(engine) as session: statement = select(Hero).where(Hero.age = 35 AND age = 35).where(Hero.age < 40) results = session.ex.. 2023. 9. 6. [Vue3] Vuex 에서 parameter 가 context? {commit}? 기본 파라메터 첫번째 파라메터는 호출할 때 따로 넘기지 않아도 됩니다. fetchQuery(context, param){ return new Promise((resolve, reject) => { axios .post('/user/query', param) .then(r=>resolve(r)) .catch(error => reject(error)) }) } 이렇게 첫번째 paramter 를 context (다른 이름도 가능 ctx 등..) 로 입력하면, 아래의 property 들이 보입니다. state 를 사용하려면 context.state getters 를 사용하려면 context.getters context 가 아니라 { } 를 사용해서 필요한것만 가져올 수도 있습니다. // fetchQuery(co.. 2023. 9. 5. 이전 1 2 3 4 5 6 7 8 ··· 58 다음 728x90 반응형