cozy

  • 홈
  • 태그
  • 방명록

2023/04 2

[FastAPI] Request에서 user 정보 얻기

해당 내용은 Startlette 공식 페이지와 스택오버플로우를 참고했다. Reqeust에 유저 정보 담기 FastAPI에서 Dependency를 이용해 token에서 유저 정보를 가져오기 위해서는 Request를 사용할 수 있다. async def get_current_user(req: Request): try: token = req.headers.get("authorization") secret_key = token_settings.secret_key algorithms = token_settings.algorithm verified_token = jwt.decode(token, secret_key, algorithms=algorithms) except jwt.ExpiredSignatureError: ..

FastAPI 2023.04.23

[FastAPI] Pydantic validator의 재사용

Validator pydantic의 BaseModel을 사용하여 프론트에서 받을 Body 값을 지정하는 동시에 Body 값 중에 validator가 필요한 경우 pydantic model 안에서 정의할 수 있다. 아래의 예시는 pydantic 공식 페이지에서 제공하는 예시와 설명이다. from pydantic import BaseModel, ValidationError, validator class UserModel(BaseModel): name: str username: str password1: str password2: str @validator('name') def name_must_contain_space(cls, v): if ' ' not in v: raise ValueError('must c..

FastAPI 2023.04.21
이전
1
다음
더보기
프로필사진

cozy

  • 분류 전체보기
    • Python
    • Django
    • FastAPI
    • Docker
    • Database

Tag

delete_cookie, refactoring, wecode, FastAPI, Python, API Testing, List comprehensions, Til, first class citizen, nested function, Mixpanel, Django 초기 세팅, django, 믹스패널, token authentication, Pydantic, drf, 일급객체, corsheaders, set_cookie,

최근글과 인기글

  • 최근글
  • 인기글

최근댓글

공지사항

페이스북 트위터 플러그인

  • Facebook
  • Twitter

Archives

Calendar

«   2023/04   »
일 월 화 수 목 금 토
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

방문자수Total

  • Today :
  • Yesterday :

Copyright © AXZ Corp. All rights reserved.

티스토리툴바