django #์ฅ๊ณ #djangorestframework #DRF #viewset
-
[Django][DRF] ViewSets์ ๊ฐ๋ TECH 2021. 7. 9. 00:08
ํ์ฌ ๋๋ ์ฅ๊ณ ์ ๋ฆฌ์กํธ๋ฅผ ์ฌ์ฉํด ํ๋ก์ ํธ๋ฅผ ๊ฐ๋ฐ ์ค์ด๋ค. ๋ฐฑ์๋๋ฅผ ์ฅ๊ณ ๋ก ๊ตฌํํ๋ ์ค, ์ฌ๋ฌ ์ด๋ ค์๋ค์ด ์๊ฒจ ์ฅ๊ณ ๋ฅผ ๋ ํํํ ์ ๋ฆฌํด ๋ณด๊ณ ์ ํ๋ค. ๋ณธ ๋ด์ฉ์ Django REST Framework ๊ณต์ ๋ฌธ์๋ฅผ ๋ฒ์ญํ ๊ธ์ด๋ค. ๊ณต์ ๋ฌธ์๋ฅผ ๋ฒ์ญํ๋ ๊ณผ์ ์์ ๋ฌธ์ฅ์ด ๋งค๋๋ฝ์ง ์์ ์ ์๋ค. ^^; Viewset Django REST ํ๋ ์์ํฌ๋ฅผ ์ฌ์ฉํ๋ฉด ViewSet์ ์ฌ์ฉํด ํด๋์ค ์์์ ๊ด๋ จ์๋ ๋ทฐ๋ค์ ๋ํ ๋ก์ง์ ํฉ์น ์ ์๋ค. ๋ค๋ฅธ ํ๋ ์์ํฌ์์๋ ๊ฐ๋ ์ ์ผ๋ก ์ ์ฌํ ๊ตฌํ์ธ '๋ฆฌ์์ค'๋ '์ปจํธ๋กค๋ฌ'์ ์ ์ฌํ ๊ฐ๋ ์ด๋ค. ViewSet ํด๋์ค๋ ํด๋์ค ๊ธฐ๋ฐ View์ ํ ์ ํ์ด๊ณ , .get()์ด๋ .post() ๊ฐ์ ๋ฉ์๋ ํธ๋ค๋ฌ ๋์ .list() ๋ฐ .create()๋ฅผ ์ ๊ณตํ๋ค. ViewSet์ ๋ฉ..