router 등록: 모듈을 별도의 파일에 분리

2025. 4. 30. 22:35파이썬/FastAPI

test.py

from fastapi import APIRouter

router = APIRouter()

@router.post("/run")
async def run():
    return 'Hellow'

main.py

# 만약 /temp/test.py인 경우는 from temp.test로 해야 함
from test import router as test_router

app = FastAPI()

app.include_router(test_router, prefix='/test')

호출

/test/run

'파이썬 > FastAPI' 카테고리의 다른 글

UI 추가  (0) 2025.05.01
주요 파일 별도 저장하기  (0) 2025.04.13
로그인 추가하기  (0) 2025.04.13
FastAPI 이미지 만들기  (1) 2024.09.16
파일 다운로드 설정  (0) 2024.06.28