FastAPI 프로젝트 진행(데이터 수정 API, RedirectResponse) - 87
·
Develop/FastAPI
1. 데이터 수정 API 생성 @router.post("/edit-todo/{todo_id}", response_class=HTMLResponse) async def edit_todo_commit(request: Request, todo_id: int, title: str = Form(...), description = Form(...), priority: int = Form(...), db: Session = Depends(get_db)): todo_model = db.query(models.Todos).filter(models.Todos.id == todo_id).first() todo_model.title = title todo_model.description = description todo_mo..
FastAPI 프로젝트 진행(DB 데이터 화면 뿌리기) -86
·
Develop/FastAPI
1. API 수정 @router.get("/edit-todo/{todo_id}", response_class=HTMLResponse) async def edit_todo(request: Request, todo_id: int, db: Session = Depends(get_db)): todo = db.query(models.Todos).filter(models.Todos.id == todo_id).first() return templates.TemplateResponse("edit-todo.html", {"request":request, "todo": todo}) 2. edit-todo.html 수정 {% include 'layout.html' %} Let's edit your todo! Title De..
FastAPI 프로젝트 진행(데이터 생성 API, RedirectResponse) - 85
·
Develop/FastAPI
1. todos.py 데이터 생성 API 추가 #라이브러리 추가 from fastapi import Form from starlette.responses import RedirectResponse from starlette import status #새로운 API @router.post("/add-todo", response_class=HTMLResponse) async def create_todo(request: Request, title: str = Form(...), description: str =Form(...), priority: int = Form(...), db: Session = Depends(get_db)): todo_model = models.Todos() todo_model.titl..
FastAPI 프로젝트 진행(HTML 렌더링, DB 연결)- 84
·
Develop/FastAPI
1. todos.py 수정 #라이브러리 추가 from sqlalchemy.orm import Session from fastapi import Depends #API 수정 @router.get("/", response_class=HTMLResponse) async def read_all_by_user(request: Request, db: Session = Depends(get_db)): #Todos 테이블 데이터 전체 호출 todos = db.query(models.Todos).filter(models.Todos.owner_id == 6).all() #Todos 테이블 데이터 렌더링 return templates.TemplateResponse("home.html", {"request":request, ..
FastAPI 프로젝트 진행(추가 레이아웃, 추상화) - 83
·
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 base.css bootstrap.css bootstrap.js jquery-slim.js popper.js auth.py todos.py 추가적으로 코드를 분리해서 간결하게 만들어보자 templates 디렉터리 하위에 navbar.html 생성 1. navbar.html 수정 layout.html에서 navbar 부분만 잘라내서 붙인다. Todo App Home ..
FastAPI 프로젝트 진행(레이아웃) - 82
·
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 base.css bootstrap.css bootstrap.js jquery-slim.js popper.js auth.py todos.py html상 중복된 코드를 Jinja를 통해 간결하게 만들자 templates 디렉터리 하위에 layout.html 생성 1. layout.html 수정 html상 중복되었던 navbar와 script문을 기입 Todo App Home {% block..
FastAPI 프로젝트 진행(HTML 렌더링 API 생성)- 81
·
Develop/FastAPI
HTML 렌더링을 API로 만들어서 호출해 보자 FastAPI에서 직접 HTML로 응답을 반환하려면 HTMLResponse 사용한다. HTMLResponse의 매개변수 response_class로 전달한다. 1. todos.py 수정 import sys sys.path.append("..") from fastapi import APIRouter, Request import models from database import engine, SessionLocal from fastapi.responses import HTMLResponse from fastapi.templating import Jinja2Templates router = APIRouter( prefix="/todos", tags=['todos..
FastAPI 프로젝트 진행(로그인, 회원가입 프론트 구현) - 80
·
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 base.css bootstrap.css bootstrap.js jquery-slim.js popper.js auth.py todos.py 로그인 및 회원가입 페이지 만들기 templates 디렉터리 하위에 login.html, register.html 생성 1. login.html 수정 Todo App Home Login Username Password Login Register? 2. HTML 렌더링(t..
FastAPI 프로젝트 진행(form 생성 / 수정) - 79
·
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 base.css bootstrap.css bootstrap.js jquery-slim.js popper.js auth.py todos.py form을 사용해서 화면 구성(생성 / 수정) templates 디렉터리 하위에 add-todo.html, edit-todo.html 생성 1. add_todo.html 수정 Todo App Home Make a new todo Title Description Priority 1 2 3 4 5 Add new tod..
FastAPI 프로젝트 진행(Navbar, Table 프론트 구현) - 78
·
Develop/FastAPI
Navbar 만들기, todo 리스트 만들기 ※ 304 Not Modified 에러 시 이미지, 파일 등이 캐싱되어 있기에 추가적으로 캐시를 진행하지 않는다. 해결방법은? 로컬 캐시를 지워준다. 크롬 브라우저 사용 시 설정 >> 개인 정보 보호 및 보안 >> 인터넷 사용 기록 삭제 >> 캐시 된 이미지 및 파일 삭제 위 방법으로 해결이 안 된다면? 크롬 브라우저 시크릿 모드로 해보자 1. Navbar 생성 Todo App Home 2. todo 리스트 만들기 Your Todos! List of your Todos! Information regarding stuff that needs to be complete Actions Info # 1 Take out the trash Complete Delete 2..