Django 시작하기(생성 명령어, Setup 연습) - 1
·
Develop/Django
IDE: VS Code 버전: Python 3.11 운영체제: MacOS 가상환경 구성(내부 라이브러리) python -m venv .venv 가상환경 구성(외부 라이브러리) pip install virtualenv virtualenv myenv or virtualenv .venv --python={파이썬 버전} 가상환경 활성화 source .venv/bin/activate 가상환경 비활성화 deactivate 가상환경 패키지 문서 https://docs.python.org/3/tutorial/venv.html 생성 명령어 구분 명령어 장고 설치 pip3 install django or python3 -m pip install Django 장고 프로젝트 생성 django-admin startproject..
FastAPI 프로젝트 마무리(Render, Elephantsql, 배포하기) - 97
·
Develop/FastAPI
Render란?개발자는 코딩에 집중할 수 있고 인프라에 대해 걱정하지 않아도 된다. 플랫폼 서비스로 개발자가 클라우드 환경해서 애플리케이션을 구축, 실행 및 운영할 수 있도록 도와준다. 유료 버전, 무료 버전도 있으며 현재 글에서는 무료버전을 다룰 예정이다. Render 기능코드 개발 시스템 CI(Continuous Integration) / CD(Continuous Deployment)확장성과 부하분산 Render 흐름Local Git >> GitHub >> render >> 서비스 및 사용자들  비슷한 클라우드 플랫폼AWS, Azure, Google Cloudhttps://github.com/seokcode/fastapi 1. requirement.txt 만들기python 프로젝트의 의존성 정보가 담..
FastAPI 프로젝트 git 올리기(git 명령어) - 96
·
Develop/FastAPI
git 명령어 모음Git CommandDetailsgit init비어있는 새 레파지토리를 초기화 한다. 즉, 현재 디렉터리를 git이 인식한다.(git 저장소가 생성 됨)git add .git add {파일 / 디렉터리 경로} => 디렉터리의 변경 내용의 일부만 스테이징 영역으로 보낼 때git add . => 현재 디렉터리 이하의 모든 변경 내용을 스테이징 영역으로 보낼 때git add -A =>  최상위 디렉토리 부터 모든 변경 내용을 스테이징 영역으로 보낼 때git add -p => 변경 내용을 하나씩 원하는 만큼 스테이징 영역으로 보낼 때git commit -m "{메세지}"스테이징 영역에 추가한 파일을 commit을 통해 트랜잭션을 완료한다.git branch -M mainmain 브랜치 생성gi..
FastAPI 프로젝트 진행(비밀번호 변경, 라우터 추가) - 95
·
Develop/FastAPI
프로젝트 디렉터리 구조 fastapi todoapp main.py database.py models.py todos.db templates static routers todo css js home.html add-todo.html edit-todo.html login.html register.html layout.html navbar.html edit-user-password.html base.css bootstrap.css bootstrap.js jquery-slim.js popper.js auth.py todos.py users.py templates 하위에 edit-user-password.html 생성 routers 하위에 users.py 생성 1. users.py 기본 세팅 import sys ..
쿠키와 세션의 정의
·
Develop/기초지식
사용자(클라이언트)의 인증 정보를 포함하고 있는 Cookie와 Session 쿠키의 탄생 사용자(클라이언트)의 IP 주소와 User-Agent는 매번 변경되며 고유하지 않은 정보로, HTTP 프로토콜의 Connectionless와 Stateless 특징 때문에 웹 서버는 사용자(클라이언트)를 기억할 수 없다. HTTP 프로토콜 Connectionless 하나의 요청에 하나의 응답을 한 후에 연결을 종료한다. Stateless 통신이 끝난 후 상태 정보를 저장하지 않는다. => 서버가 많은 사용자(클라이언트) 연결을 추적할 필요가 없기 때문에(HTTP 확장 가능) => 이런 특성들 인해 HTTP상에서 상태 유지를 위해서 쿠키가 탄생했다. => 쿠키는 사용자(클라이언트)의 정보와 상태를 담고 있다. 쿠키의 ..
FastAPI 프로젝트 진행(코드 정리) - 94
·
Develop/FastAPI
1. auth.py 코드 정리 import sys sys.path.append('..') from starlette.responses import RedirectResponse from fastapi import Depends, HTTPException, status, APIRouter, Request, Response, Form from typing import Optional import models from passlib.context import CryptContext from sqlalchemy.orm import Session from database import SessionLocal, engine from fastapi.security import OAuth2PasswordRequestFo..
FastAPI 프로젝트 진행(회원가입 기능 구현) - 93
·
Develop/FastAPI
1. auth.py 새로운 API 생성 @router.post("/register", response_class=HTMLResponse) async def register_user(request: Request, email: str = Form(...), username: str = Form(...), firstname: str = Form(...), lastname: str = Form(...), password: str = Form(...), password2: str = Form(...), db: Session = Depends(get_db)): validation1 = db.query(models.Users).filter(models.Users.username == username).first()..
FastAPI 프로젝트 진행(로그아웃 기능 구현) - 92
·
Develop/FastAPI
1. auth.py 새로운 API 생성 @router.get("/logout") async def logout(request: Request): msg = "logout Successful" response = templates.TemplateResponse("login.html", {"request":request, "msg":msg}) response.delete_cookie(key="access_token") return response response를 직접 return delete_cookie로 현재 cookie에 저장된 JWT를 삭제 2. 웹 확인 API 호출을 통해서 알럿과 함께 cookie상의 데이터가 없어진 것을 확인할 수 있다. 3. navbar.html에 로그아웃 버튼 추가 Todo ..
FastAPI 프로젝트 진행(로그인 추가, 쿠키 세션) - 91
·
Develop/FastAPI
1. auth.py의 함수 수정async def get_current_user(request: Request): try: token = request.cookies.get("access_token") if token is None: return None payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM]) username: str = payload.get("sub") user_id: int = payload.get("id") if username is None or user_id is None: return No..
FastAPI 프로젝트 진행(로그인 기능 구현 API) - 90
·
Develop/FastAPI
1. auth.py에 새로운 클래스 추가 class LoginForm: def __init__(self, request: Request): self.request: Request = request self.username: Optional[str] = None self.password: Optional[str] = None async def create_oauth_form(self): form = await self.request.form() self.username = form.get("email") self.password = form.get("password") await는 async 함수 안에서만 동작하며(일반 함수에는 동작 X), await를 만나면 self.request.form()가 처리될 ..