본문 바로가기
profile_image

Gnuboard6

__init__.py 와 routers.py 관계?

페이지 정보

작성자 이노힐
댓글 0건 조회 13회
작성일 2025-04-08 09:25:04

본문

__init__.py와 routers.py의 관계를 분석해보겠습니다.
먼저 두 파일의 내용을 확인해보겠습니다.

Read __init__.py

L1-50

Read routers.py

L1-50

두 파일의 관계를 분석해보면 다음과 같습니다:
  1. 구조적 차이:
  • api/v1/routers/__init__.py: API v1 버전의 라우터들을 모아서 관리
  • core/routers.py: 템플릿 기반의 웹 라우터들을 모아서 관리
  1. 공통점:
  • 두 파일 모두 FastAPI의 APIRouter를 사용
  • 라우터들을 모아서 하나의 메인 라우터로 통합하는 역할
  • 의존성 주입을 사용하여 공통 기능 적용
  1. 차이점:
  • API 엔드포인트들을 관리
  • /api/v1 prefix 사용
  • check_use_api 의존성 사용
  • 태그 기반으로 API 문서화 지원
  • 템플릿 기반 웹 페이지 라우터들을 관리
  • /bbs prefix 사용
  • check_use_template 의존성 사용
  • include_in_schema=False로 설정하여 API 문서에서 제외
  1. 라우터 등록 방식:

    python

    Apply to routers.py

       # api/v1/routers/__init__.py

       router.include_router(board_new.router, prefix="/board-new", tags=[Tags.BOARD_NEW])

       # core/routers.py

       router.include_router(board_new_router, prefix="/bbs", tags=["board_new"])

  1. 의존성 차이:

    python

    Apply to routers.py

       # api/v1/routers/__init__.py

       dependencies=[Depends(check_use_api), Depends(set_current_connect)]

       # core/routers.py

       dependencies=[Depends(check_use_template),

                    Depends(set_current_connect),

                    Depends(set_template_basic_data)]

  1. 목적:
  • api/v1/routers/__init__.py: REST API 엔드포인트 제공
  • core/routers.py: 웹 페이지 템플릿 기반 라우팅 제공
이 두 파일은 각각 다른 목적을 가진 라우터들을 관리하며, FastAPI 애플리케이션의 두 가지 주요 인터페이스(API와 웹 페이지)를 제공하는 역할을 합니다.

댓글목록

등록된 댓글이 없습니다.

댓글쓰기

내용

방문자 집계

  • 오늘 605
  • 어제 646
  • 최대 849
  • 전체 30,146

Copyright © innohealonline.com. All rights reserved.