Search

Django ๊ฐœ๋ฐœํ™˜๊ฒฝ ์„ค์น˜ - Python ํŒŒ์ด์ฌ ์›น๊ฐœ๋ฐœ

Django ๊ฐœ๋ฐœํ™˜๊ฒฝ ์„ค์น˜ - Python ํŒŒ์ด์ฌ ์›น๊ฐœ๋ฐœ

๊ฐœ๋ฐœํ™˜๊ฒฝ ์„ค์น˜

โ€ข
IDE ์„ค์น˜
โ—ฆ
VS CODE
โ€ข
Python ์„ค์น˜
โ€ข
Django ์„ค์น˜

์žฅ๊ณ  ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

โ€ข
ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
โ€ข
์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ƒ์„ฑ
โ€ข
๊ธฐ๋ณธ ์„ค์ •

์›น ์„œ๋ฒ„ ์‹คํ–‰ - runserver

IDE ์„ค์น˜ - VS CODE

1.
VS CODE ๊ฒ€์ƒ‰
3.
VS CODE ์„ค์น˜
a.
์„ค์น˜ํ•˜๊ธฐ
b.
์„ค์น˜ํ™•์ธ

Python ์„ค์น˜

1.
Python ๊ฒ€์ƒ‰
3.
Python ์„ค์น˜
a.
์„ค์น˜ํ•˜๊ธฐ
b.
์„ค์น˜ํ™•์ธ
i.
์ปค๋งจ๋“œ(ํ„ฐ๋ฏธ๋„)
python -V
Java
๋ณต์‚ฌ

Django ์„ค์น˜

1.
pip ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ์žฅ๊ณ  ์„ค์น˜
pip install Django
Shell
๋ณต์‚ฌ
2.
์ด์ „ ๋ฒ„์ „์—์„œ ์—…๊ทธ๋ ˆ์ด๋“œ
pip install Django --upgrade
Shell
๋ณต์‚ฌ
3.
VS CODE Django ํ™•์žฅ ์„ค์น˜ (VS CODE Django Extension)
a.
ํ™•์žฅ (Extension)
b.
โ€œDjangoโ€ ๊ฒ€์ƒ‰
c.
install [์„ค์น˜]

Django ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

โ€ข
ํ”„๋กœ์ ํŠธ๋ช… : sample
django-admin startproject sample
Shell
๋ณต์‚ฌ

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ƒ์„ฑ

cd sample python manage.py startapp app
Shell
๋ณต์‚ฌ

๊ธฐ๋ณธ ์„ค์ •

1.
settings.py
a.
๊ฐœ๋ฐœ/์šด์˜ ๋ชจ๋“œ ์„ค์ •
# ๊ฐœ๋ฐœ๋ชจ๋“œ(True), ์šด์˜๋ชจ๋“œ(False) DEBUG = True
Shell
๋ณต์‚ฌ
b.
ํ˜ธ์ŠคํŠธ ์ฃผ์†Œ ์„ค์ •
# ํ˜ธ์ŠคํŠธ ์ฃผ์†Œ ์„ค์ • ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
Shell
๋ณต์‚ฌ
c.
์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋“ฑ๋ก
# ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋“ฑ๋ก INSTALLED_APPS = [ # app ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋“ฑ๋ก 'app.apps.AppConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ]
Shell
๋ณต์‚ฌ
d.
๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—”์ง„ ์„ค์ •
# ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—”์ง„ ์„ค์ • DATABASES = { 'default': { # Sqllite3 ๋กœ DB์—”์ง„ ์„ค์ • 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } }
Shell
๋ณต์‚ฌ
e.
ํƒ€์ž„์กด ์„ค์ •
# ํƒ€์ž„์กด ์„ค์ • # TIME_ZONE = 'UTC' TIME_ZONE = 'Asia/Seoul'
Shell
๋ณต์‚ฌ
2.
๊ธฐ๋ณธ ํ…Œ์ด๋ธ” ์ƒ์„ฑ (๋งˆ์ด๊ทธ๋ ˆ์ด์…˜)
python manage.py migrate
Shell
๋ณต์‚ฌ

์›น์„œ๋ฒ„ ์‹คํ–‰ํ•˜๊ธฐ - runserver

์›น์„œ๋ฒ„ ๊ธฐ๋ณธ ์‹คํ–‰ (๊ธฐ๋ณธ ์ฃผ์†Œ : 127.0.0.1, ๊ธฐ๋ณธ ํฌํŠธ : 8000)
python manage.py runserver
Shell
๋ณต์‚ฌ
ํฌํŠธ๋ฒˆํ˜ธ ์ง€์ • ์‹คํ–‰
python manage.py runserver 8000
Shell
๋ณต์‚ฌ
๋ธŒ๋ผ์šฐ์ €
http://127.0.0.1:8000 http://localhost:8000
Shell
๋ณต์‚ฌ
๋‹ค์Œ ํŽ˜์ด์ง€
์žฅ๊ณ  ๊ด€๋ฆฌ์ž ์ƒ์„ฑํ•˜๊ธฐ