[Django] - 1. Django ์‹œ์ž‘ํ•˜๊ธฐ

์ตœ์ฐฝ์šฐยท2022๋…„ 8์›” 13์ผ
0

Django

๋ชฉ๋ก ๋ณด๊ธฐ
1/10
post-thumbnail

๐Ÿ™Œ HTTP ์ฐธ๊ณ 

๐Ÿ“œ Django ์‚ฌ์šฉ๋ฒ•์„ ์•Œ์•„๋ณด์ž.

๊ธฐ๋ณธ์„ธํŒ…

vscode๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ€์ƒํ™˜๊ฒฝ ๋งŒ๋“ค๊ณ  ๊ฐ€์ƒํ™˜๊ฒฝ์— ์žฅ๊ณ ์„ค์น˜ํ•˜๊ธฐ

  1. ๊ฐ€์ƒํ™˜๊ฒฝ์ƒ์„ฑ (python 3.6) ์™„๋ฃŒ (conda ์‚ฌ์šฉ)
    • ํ„ฐ๋ฏธ๋„ ์—ด๊ธฐ (command + shift + ~)
    • bash terminal open
    • conda create -n Django python=3.6
    • conda activate Django
    • conda install django
  2. ๊ฒฝ๋กœ์ƒ์„ฑ
    • ๊ฒฝ๋กœ : django/myproject/django-start/ (๋‚ด๊ฐ€ ์ž„์˜๋กœ์ •ํ•œ๊ฑฐ)

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

์ฐธ๊ณ 
django-admin : ์‹คํ–‰๊ฐ€๋Šฅํ•œ sumcommand ๋ชฉ๋ก ํ™•์ธ๊ฐ€๋Šฅ

๐Ÿ“– ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

์ฝ”๋“œ ์ˆ˜ํ–‰ ๋””๋ ‰ํ† ๋ฆฌ : django/myproject/django-start/

(๊ฐ€์ƒํ™˜๊ฒฝ๋ช…) django-admin startproject ํ”„๋กœ์ ํŠธ๋ช… ํ”„๋กœ์ ํŠธ์ƒ์„ฑํ• ๊ฒฝ๋กœ

(django) django-admin startproject project . 

ํ˜„์žฌ๊ฒฝ๋กœ๋ฅผ ์ž‘์—…๊ณต๊ฐ„์œผ๋กœ ์„ค์ •ํ• ๊ฑฐ๋ฉด ํ”„๋กœ์ ํŠธ์ƒ์„ฑ๊ฒฝ๋กœ์— "." ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

์•„๋ž˜ ๊ฒฐ๊ณผ๋ฌผ์„ ๋ณด๋ฉด, project ํด๋”์™€ manage.py ์ƒ์„ฑ๋˜์—ˆ์Œ

  1. ํ”„๋กœ์ ํŠธ
    • ๋‚ด๊ฐ€ ๋งŒ๋“ค ์›น ํ”„๋กœ์ ํŠธ์˜ ์ •๋ณด๋ฅผ ์ „๋ถ€ ๋‹ด๊ฒŒ๋˜๋Š” ํด๋”
  2. manage.py
    • manage.py์˜ Docstring์„ ๋ณด๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ๋˜์–ด์žˆ๋Š”๋ฐ
    • Django's command-line utility for administrative tasks
    • ์ฆ‰ ์žฅ๊ณ ๊ด€๋ จ ๋ช…๋ น์–ด๋“ค์ด ๋ชจ์—ฌ์žˆ๋Š” ๋ชจ๋“ˆ์ด๋ผ ๋ณด๋ฉด๋œ๋‹ค.
    • ๋”ฐ๋ผ์„œ ์žฅ๊ณ ๊ด€๋ จ ๋ช…๋ น์–ด ์ˆ˜ํ–‰์‹œ python manage.py ์‚ฌ์šฉํ• ๋ช…๋ น์–ด ์ฒ˜๋Ÿผ ์‚ฌ์šฉ๊ฐ€๋Šฅ

๐Ÿ“– ํ”„๋กœ์ ํŠธ ์‹œ์ž‘

(django) python manage.py runserver

๐Ÿ“• ์žฅ๊ณ  ์•ฑ ์ƒ์„ฑ

ํ”„๋กœ์ ํŠธ์™€ ๋”๋ถˆ์–ด ์—ฌ๋Ÿฌ๊ธฐ๋Šฅ ๋‹ด๋‹นํ•˜๋Š” ์•ฑ์œผ๋กœ ๊ตฌ์„ฑ๊ฐ€๋Šฅ

(django) python manage.py startapp app

์•„๋ž˜๊ฒฐ๊ณผ๋ฌผ์„ ๋ณด๋ฉด app ํด๋”๊ฐ€ ์ƒ์„ฑ๋˜์—ˆ์Œ.

๐Ÿ“• ์ „์ฒด๊ณผ์ • ์ •๋ฆฌ

  1. ๊ธฐ๋ณธ์„ธํŒ… ( ๊ฐ€์ƒํ™˜๊ฒฝ, ์žฅ๊ณ ์„ค์น˜, ๊ฒฝ๋กœ๊ตฌ์„ฑ )
  2. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ > django-admin startproject ํ”„๋กœ์ ํŠธ๋ช… ๊ฒฝ๋กœ
  3. ์•ฑ ์ƒ์„ฑ > python manage.py startapp ์•ฑ๋ช…
profile
์œ ๋Šฅํ•œ ๊ฐœ๋ฐœ์ž๊ฐ€ ๋˜๊ณ  ์‹ถ์€ ํ—ฌ๋ฆฐ์ด

0๊ฐœ์˜ ๋Œ“๊ธ€