Django
์ฅ๊ณ ๋ Python์ธ์ด๋ฅผ ์ด์ฉํ ๊ฒฝ๋ ๊ฐ๋ฐ ํ๋ ์์ํฌ์ด๋ค.
๊ฐ์ฅ ๋์ค์ ์ผ๋ก ๋ง์ด ์ฌ์ฉํ๋ Spring MVC ํ๋ ์์ํฌ๋ฅผ ๊ฒฝ๋ํ ์์ผ MTVํํ๋ก ๋์ด์๋ค.
๋์ด์ ์ค๋ช ์ด ํ์ ์๊ณ ๊ทธ๋ฅ ๊ฒฝ๋ํ๋์ด ๊ฐ๋ฐ ๊ธฐ๊ฐ์ ํ๊ธฐ์ ์ผ๋ก ๋จ์ถ์์ผ์ค๋ค.
-Model : ๋ฐ์ดํฐ์ ์ ์ฅ ๋ถ๋ถ์ผ๋ก MVC์์์ M์ ์ญํ ๊ณผ ๊ฐ๋ค.
-Template : MVCํจํด์ View ์ญํ ๋ก ์ฌ์ฉ์์์ ๋ณด์ฌ์ง๋ ๋ถ๋ถ์ด๋ค.
-View : MVCํจํด์ View์๋ ๋ค๋ฅด๊ฒ url ํ์ฑ์ญํ ์ ํด์ฃผ๊ณ Model๋ก ๋ถํฐ ๋ฐ์ดํฐ๋ฅผ ์ฝ๊ฒ ๋ฐ์์ Template์ผ๋ก ๋ฟ๋ ค์ฃผ๋ ์ญํ ์ ํ๋ค.
Django ๊ฐ๋ฐ์ ์งํํ๊ธฐ ์ํด ์๋ 3๊ฐ์ง ~ 4๊ฐ์ง ์ธํ ์ด ์ฌ์ ์ ํ์ํ๋ค.
-Python ์ค์น (์๋์ฝ๋ค : https://myjamong.tistory.com/38, ์ผ๋ฐ ํ์ด์ฌ ์ค์นํด๋ ๋ฌด๊ด)
-Python ๊ฐ์ํ๊ฒฝ ์ธํ (https://myjamong.tistory.com/97)
-์๋ํฐ (Atom ์ฌ์ฉ์ ์๋ ์ฐธ์กฐ)
-Database(์ ํ์ฌํญ)
Atom ์๋ํฐ
์ฌ๋ฌ ์๋ํฐ์ค ํ์๋ Django๊ฐ๋ฐ์ ์งํํ ๋ Atom ์๋ํฐ๋ฅผ ์ฌ์ฉํ๊ฒ ๋ค.
A hackable text editor for the 21st Century
At GitHub, we’re building the text editor we’ve always wanted: hackable to the core, but approachable on the first day without ever touching a config file. We can’t wait to see what you build with it.
atom.io
ํด๋น ์ด์์ฒด์ ์ ๋ง๊ฒ Atom์๋ํฐ๋ฅผ ์ค์นํด์ค๋ค.
์ํฐ ์๋ํฐ๋ฅผ ์ฌ์ฉํ๋ฉด ํฐ๋ฏธ๋์ด๋ ์ปค๋งจ๋์ฐฝ์์ atom . ๋ช ๋ น์ด๋ฅผ ์คํ์์ผ ํด๋น ๋๋ ํ ๋ฆฌ ํ์๋ก ํ์ผ๋ค์ ์ ๋ถ ์ด์ด์ค๋ค.
Atom ์๋์์ฑ๊ธฐ๋ฅ Install
ํธ์ํ ๊ฐ๋ฐํ๊ฒฝ์ ๊ฐ์ถ๊ธฐ ์ํด Atom์์ ์ค์น๊ฐ๋ฅํ ํจํค์ง ๋ช๊ฐ๋ฅผ ๋ฐ์์ค๋ค.
1. Python ์๋์์ฑ ๊ธฐ๋ฅ(autocomplete-python)
2. Django ์๋์์ฑ ๊ธฐ๋ฅ(atom-django)
ํจํค์ง ์ค์น๋ Atom - Preferences - Install ํญ์์ ๊ฒ์์ ํตํด ์ค์น๊ฐ ๊ฐ๋ฅํ๋ค.
python ์๋์์ฑ ํจํค์ง
django ์๋์์ฑ ํจํค์ง
Django ์ค์น
์ฅ๊ณ ์ค์น๋ ๋งค์ฐ ๊ฐ๋จํ๋ค.
๊ฐ์ํ๊ฒฝ์ ์ ์ํ์ฌ pip๋ฅผ ์ด์ฉํด์ ์ค์นํ๋ค.
๊ฐ์ํ๊ฒฝ ์ ์
workon python3_env
์ฅ๊ณ ์ค์น
pip install django
์ฅ๊ณ ์ค์น ๋๋ฌ๋ค.
Django ํ๋ก์ ํธ ์์ฑ ๋ฐ ์๋ฒ ์คํ
Django ๋ช ๋ น์ด๋ฅผ ์ด์ฉํด์ ํ๋ก์ ํธ๋ฅผ ์์ฑํ๊ณ App๋ ์์ฑ์ ํ๋ค.
๊ธฐํ ๊ด๋ฆฌ๋ฅผ ์ํด Django ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ง๋ง, ์ด๊ธ์์๋ ๊ฐ๋จํ๊ฒ ์คํ๊น์ง๋ง ํ์ํ ๋ช ๋ น์ด๋ค์ ์ฌ์ฉํ ๊ฑฐ๋ค.
Django ํ๋ก์ ํธ ์์ฑ
first_project๋ผ๋ ์ด๋ฆ์ผ๋ก ํ๋ก์ ํธํ๋๋ฅผ ์์ฑํ๋ค.
django-admin startproject first_project
ํด๋น ํ๋ก์ ํธ์ ๋ชจ๋ ์ค์ ์ ์๋ ๋๋ ํ ๋ฆฌ์ ํ์ผ๋ค์์ ์ค์ ํ๋ค.
Django App ์์ฑ
first_app๋ผ๋ ์ด๋ฆ์ผ๋ก Appํ๋๋ฅผ ์์ฑํ๋ค. ๋ช ๋ น์ ํ๋ก์ ํธ ์์ฑ์ ๊ฐ์ด ๋ง๋ค์ด์ง manage.py ํ์ผ์ ์ด์ฉํ๋ค.
./manage.py startapp first_app
App์ ๋ํ ๋ชจ๋ ํจํด์ ๊ด๋ฆฌํ๋ค.
์์ง Template์ ๋ํ ๊ตฌ์กฐ๋ ์๋๋ฐ... ๊ฐ๋ฐ์ ์ถ๊ฐํ๋ค.
์๋ฒ์คํ
์ด์์์ด ์์ฑ์ด ๋์๋์ง ํ์ธํ๊ธฐ ์ํด ์๋ฒ๋ฅผ ์คํํด๋ณธ๋ค.
ํน์ ํฌํธ๋ก ์ง์ ํด์ ์คํํ๊ธฐ ์ํด์๋ runserver ๋ช ๋ น ๋ค์ ํด๋น ํฌํธ๋ฅผ ์ธ์๋ก ์ถ๊ฐํด์ฃผ๋ฉด ๋๋ค. default๋ 8000๋ฒ ํฌํธ์ด๋ค.
./manage.py runserver
์๋์ ๊ฐ์ด ๊ธฐ๋ณธ ์ธ๋ฑ์ค ํ๋ฉด์ด ์์ฑ๋๋ฉด ์ฑ๊ณต์ด๋ค.
์คํ์ ์๋์ ๊ฐ์ด migration๊ด๋ จ๋ warning์ด ๋ฐ์ํ ์ ์๋ค.
์ด๋ ๊ด๋ฆฌ์ ๋ฐ ๊ถํ, ์ธ์ , DB๊ด๋ จ๋ ์ ๋ณด๋ค์ ๋ฐ์ํ์ง ์์ ๋ฐ์ํ๋ค.
DB ์ค์ ๊ด๋ จ๋ ๊ธ์ ์์ฑํ๋ฉด์ ์ด๋ถ๋ถ์ ๋ํ ๋ช ๋ น ๋ฐ ์ค๋ช ์ ์งํํ ๊ฑฐ๋ค.
๋๊ธ