๐Ÿš€ Languege/Django-Python

[Django #5] ๊ด€๋ฆฌ ํŽ˜์ด์ง€ ์ ‘์†ํ•˜๊ธฐ!

mini_world 2021. 1. 19. 13:12
๋ชฉ์ฐจ ์ ‘๊ธฐ

 

์ด๋ฒˆ ๋‹จ๊ณ„์—์„œ๋Š” ๊ด€๋ฆฌํŽ˜์ด์ง€์— ์ ‘์†ํ•ด์„œ ์ด๊ฒƒ์ €๊ฒƒ ๋ˆŒ๋Ÿฌ๋ณด๊ณ  ํ…Œ์ŠคํŠธ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค :)

์ด ์•ž์˜ ํฌ์ŠคํŒ…๋ณด๋‹ค๋Š” ์กฐ๊ธˆ ์‰ฌ์šธ๊ฑฐ์—์š”!

์ž! ์‹œ์ž‘ํ•ด๋ด…์‹œ๋‹ค.!!

 


1. admin.py์— first_app ๋“ฑ๋กํ•˜๊ธฐ

๊ด€๋ฆฌํŽ˜์ด์ง€๋Š” ์ด๋ฒˆ ๋‹จ๊ณ„์—†์ด ๋ฐ”๋กœ ๋‹ค์Œ๋‹จ๊ณ„๋กœ ๋„˜์–ด๊ฐ€๋„  ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ first_app ์ด ๋ณด์ด์ง€ ์•Š์„๊ฑฐ์—์š” ๐Ÿ˜ญ

์ด๋ฒˆ ๋‹จ๊ณ„์—์„œ first_app์„ ๊ด€๋ฆฌ ์›นํŽ˜์ด์ง€์—์„œ๋„ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ๋„๋ก first_app/admin.pyํŒŒ์ผ์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค :)

first_app/admin.py๋ฅผ ์ˆ˜์ •ํ•˜์—ฌ ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ๋ณต์‚ฌ ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•ฉ๋‹ˆ๋‹ค.

from django.contrib import admin

from .models import Question
from .models import Choice

admin.site.register(Question)
admin.site.register(Choice)

์ด๋ ‡๊ฒŒ ์„ค์ •์„ ์ €์žฅํ•˜๋ฉด! ์™„์„ฑ์ž…๋‹ˆ๋‹ค.
์ด ๋ถ€๋ถ„์—์„œ ์ž˜๋ชป๋œ ์„ค์ •์ด ์žˆ๋‹ค๋ฉด, ์•„๋ž˜ runserver(์„œ๋ฒ„์‹œ์ž‘)๋•Œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ• ๊ฒ๋‹ˆ๋‹ค.!!!

์˜คํƒ€๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๊ฒŒ ๋‹ค์‹œํ•œ๋ฒˆ ๊ผผ๊ผผํ•˜๊ฒŒ ํ™•์ธํ•˜์„ธ์š”. ๋‹ค์Œ ๋‹จ๊ณ„๋กœ ๋„˜์–ด๊ฐ‘๋‹ˆ๋‹ค!


2. ๊ด€๋ฆฌ์ž ์ƒ์„ฑ ํ›„ ์„œ๋ฒ„์— ์ ‘์†ํ•˜๊ธฐ

๊ด€๋ฆฌ์ž์— ๋กœ๊ทธ์ธ ํ•  ์ˆ˜ ์žˆ๋Š” ์‚ฌ์šฉ์ž๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. pyCharm ์™ผ์ชฝ ์•„๋ž˜ ํ„ฐ๋ฏธ๋„์—์„œ ๋ช…๋ น์–ด ์‹คํ–‰ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

python manage.py createsuperuser

๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์‚ฌ์šฉ์ž์ด๋ฆ„/ ์ด๋ฉ”์ผ์ฃผ์†Œ/ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ƒ์„ฑ์ด ์™„๋ฃŒ ๋˜์—ˆ๋‹ค๋ฉด ์ด์ œ ์„œ๋ฒ„์— ์ ‘์†ํ•ด๋ด…์‹œ๋‹ค ;)

์•„๋ž˜ ๋ช…๋ น์–ด๋กœ ์„œ๋ฒ„๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

python manage.py runserver

์„œ๋ฒ„๊ฐ€ ์‹œ์ž‘๋˜์—ˆ์œผ๋‹ˆ. ์ ‘์†์ด ๋˜๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. ์ฃผ์˜ํ•˜์…”์•ผ ํ•  ์ ์€ ์ด๋ฒˆ์—๋Š” URL๋’ค์— /admin ๋ฅผ ๋ถ™์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์›น๋ธŒ๋ผ์šฐ์ €์—์„œ ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค.

http://localhost:8000/admin ์ ‘์† ์‹œ ์•„๋ž˜์™€ ๊ฐ™์ด ๋กœ๊ทธ์ธ ์ฐฝ์ด ๋ณด์ž…๋‹ˆ๋‹ค. ์•ž์„œ ๋งŒ๋“ค์–ด๋‘์—ˆ๋˜ myadmin ๊ณ„์ •๊ณผ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ๋กœ๊ทธ์ธ ํ•ฉ๋‹ˆ๋‹ค.

Django ๊ด€๋ฆฌ ํŽ˜์ด์ง€ ์ž…๋‹ˆ๋‹ค :)

๊ด€๋ฆฌํŽ˜์ด์ง€๊นŒ์ง€ ์ •์ƒ์ ์œผ๋กœ ์ ‘์†์ด ๋˜์—ˆ๋„ค์š”! 
๋‹ค์Œ ๋‹จ๊ณ„์—์„œ ์‚ฌ์šฉ์„ ํ•ด๋ณด๋„๋ก ํ•ฉ๋‹ˆ๋‹ค!

 


3. ๊ด€๋ฆฌํŽ˜์ด์ง€ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ :)

๊ด€๋ฆฌ์ž ์‚ฌ์ดํŠธ์— ๋กœ๊ทธ์ธํ•˜์—ฌ ์ ‘์†ํ•œ ์ƒํƒœ์ž…๋‹ˆ๋‹ค.
์•„๋ž˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด first_app ๋„ ๋ณด์ด๊ณ , ์•„๋ž˜ ์ธ์ฆ ๋ฐ ๊ถŒํ•œ๋„ ๋ณด์ด๋„ค์š”!

์ธ์ฆ ๋ฐ ๊ถŒํ•œ ๋ถ€๋ถ„์€ Django์—์„œ ์ œ๊ณตํ•˜๋Š” ์ธ์ฆ ํ”„๋ ˆ์ž„์›Œํฌ์ž…๋‹ˆ๋‹ค.
์ € ๋ถ€๋ถ„์—์„œ ์‚ฌ์šฉ์ž/๊ทธ๋ฃน์„ ์ถ”๊ฐ€, ์‚ญ์ œ, ์ˆ˜์ •์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค :)

์‚ฌ์šฉ์ž์— ๋“ค์–ด์™€๋ณด๋‹ˆ ๋กœ๊ทธ์ธํ• ๋•Œ ์‚ฌ์šฉํ–ˆ๋˜ myadmin ๊ณ„์ •์ด ๋ณด์ด๋„ค์š” :)

์ด์ œ, first_app์—์„œ ์ •์˜ํ–ˆ๋˜ ๋ชจ๋ธ(๋ฐ์ดํ„ฐ ์Šคํ‚ค๋งˆ)๋ฅผ ํ™•์ธํ•ด๋ด…๋‹ˆ๋‹ค. 
๋ฐ์ดํ„ฐ๋„ ํ•œ๋ฒˆ ๋„ฃ์–ด๋ณด๊ณ ์š”!

์ด๊ฒƒ์ €๊ฒƒ ํ•œ๋ฒˆ ๋ˆŒ๋Ÿฌ๋ณด์‹œ๋ฉด์„œ ์‚ญ์ œ๋„ ํ•ด๋ณด๊ณ  ์ˆ˜์ •๋„ ํ•ด๋ด…์‹œ๋‹ค :)


์ด๋ฒˆ ํฌ์ŠคํŒ…์€ ์—ฌ๊ธฐ๊นŒ์ง€์ž…๋‹ˆ๋‹ค.

๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค ;)

728x90