본문 바로가기

Python8

Jinja2 템플릿 활용 1) style.css 파일 적용from fastapi.staticfiles import StaticFilesfrom fastapi import FastAPIapp = FastAPI()app.mount("/static", StaticFiles(directory="static"), name="static")FastAPI가 초기화된 위치를 기준으로 /static 폴더의 경로를 설정한다.html 코드 내에서 아래와 같이 호출이 가능하다. 2) Jinja2Template 예제from pathlib import Pathfrom fastapi.templating import Jinja2Templatesfrom fastapi.responses import HTMLResponsefrom fastapi import AP.. 2024. 5. 8.
Python structlog Standard Library LoggingIdeally, structlog should be able to be used as a drop-in replacement for standard library’s logging by wrapping it. In other words, you should be able to replace your call to logging.getLogger() b...www.structlog.org이전 글에서 작성했던 파이썬 내장 라이브러리 logging으로 구현했던 것을 structlog로 구현할 수 있다. Python logging파이썬에서도 날짜 별로, 특정 주기마다 로그 파일을 자동으로 생성할 수 있다.(trace Id도 설정하면 좋으련만...)구글링을 하면서 정리한.. 2024. 5. 3.
Github Action & 도커 허브에 이미지 전송 name: action nameon: push: branches: - mainjobs: build: runs-on: ubuntu-latest steps: - name: Login to Dockerhub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - uses: actions/checkout@v3 - run: docker build -t ${{ secrets.DOCKER_USERNAME }}/server-test -f ./server.. 2024. 5. 1.
map(), filter(), pipe()를 활용하여 데이터 다루기 map(), filter() 함수는 리스트 안의 데이터를 내가 원하는 대로 추출하거나 변형시킬 수 있습니다.def square(num): return num**2number_list = [1, 2, 3, 4, 5]result = map(square, number_list)print(result) # # for loop -> [1, 4, 9, 16, 25]print(list(result)) # [1, 4, 9, 16, 25]# 람다result = list(map(lambda x: x**2, number_list))print(result) # [1, 4, 9, 16, 25]map()의 리턴 데이터 타입은 map objectfilter() 또한 filter object 리스트 to 리스트를 통해 DB에.. 2024. 4. 8.