๐ฆ ๋ด์ผ๋ฐฐ์์บ ํ/WIL(Week I Learned) WIL_220612_ํ ํ๋ก์ ํธ Django - ๋ฐฐ์ด ๋ด์ฉ ์ฌ์ฉ์ ์ ์ ํจ์ ์ค์ ์ถ์ฒ : http://daplus.net/python-django-%ED%85%9C%ED%94%8C%EB%A6%BF-%EB%82%B4%EC%97%90%EC%84%9C-%EC%9D%B8%EB%8D%B1%EC%8A%A4%EB%A1%9C-%EB%AA%A9%EB%A1%9D-%ED%95%AD%EB%AA%A9%EC%9D%84-%EC%B0%B8%EC%A1%B0%ED%95%A9%EB%8B%88/ [python] Django ํ ํ๋ฆฟ ๋ด์์ ์ธ๋ฑ์ค๋ก ๋ชฉ๋ก ํญ๋ชฉ์ ์ฐธ์กฐํฉ๋๊น? - ๋ฆฌ๋ทฐ๋๋ผ ์ด๊ฒ์ ๊ฐ๋จ ํ ์ ์์ง๋ง ์ฃผ์๋ฅผ ๋๋ฌ ๋ณด์์ง๋ง ๋ต์ ์ฐพ์ ์ ์์์ต๋๋ค. Django ํ ํ๋ฆฟ์ ๋ชฉ๋ก์์ ๋จ์ผ ํญ๋ชฉ์ ์ฐธ์กฐํ๋ ๊ฐ์ฅ ์ข์ ๋ฐฉ๋ฒ์ ๋ฌด์์ ๋๊น? ์ฆ {{ data[0] }}, ํ ํ๋ฆฟ ์ธ์ด ๋ด์์ ํด๋น daplus.net ์ถ๊ฐ ์ ๋ณด ) ์ปค์คํ ํ ํ๋ฆฟ ํํฐ : https://docs.djangoproject.com/en/dev/howto/custom-template-tags/ How to create custom template tags and filters | Django documentation | Django Django The web framework for perfectionists with deadlines. Overview Download Documentation News Community Code Issues About โฅ Donate docs.djangoproject.com - ๋ฐ๋ณต๋ฌธ์ ํตํด ๋ฐ์์ฌ ์ ๋ณด๊ฐ ๋ฆฌ์คํธ ํํ๋ก ๋ถ๋ฌ์์ง๋ ๊ฒฝ์ฐ ํด๋น ๋ฆฌ์คํธ ์ ๋ณด๋ฅผ ๋์ดํด์ ์ฌ์ฉํ ์ ์๋๋ก ํ๊ธฐ ์ํด ์ฌ์ฉ์ ์ ์ ํจ์๋ฅผ ๋ง๋ค์๋ค. # templatetags / index.py from django import template register = template.Library() @register.filter def index(indexable, i): return indexable[i] - ์ด๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์ settings.py ๋ฅผ ์ค์ ํ๋ค. - libraries : index: templatetags.index ์ถ๊ฐ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR / 'templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], 'libraries':{ 'index': 'templatetags.index', } } } ] - django ํ ํ๋ฆฟ์ {% load index %} ๊ตฌ๋ฌธ์ ์ถ๊ฐ - ์๋ก my_list [x] ๊ฐ ์๋ค๋ฉด {{ my_list|index:x }} ์ผ๋ก ์ฌ์ฉํ ๋ฆฌ์คํธ๋ฅผ ๋์ - ์์ ๊ธฐ๋ฅ์ ์ฌ์ฉํ๊ณ ์ ํ๋ ์ด์ ๋ ์ถ๋ ฅํ๊ณ ์ ํ๋ ํฌ๋กค๋ง ๋ฐ์ดํฐ๊ฐ ๋ฆฌ์คํธ ํ์์ผ๋ก ๋ฐ์์์ ธ์ ๊ทธ ๋ฆฌ์คํธ๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ํ์ผ๋, ํฌ๋กค๋ง ๋ ๋ฐ์ดํฐ๋ฅผ db ์ ์ ์ฅํ์ฌ ๊ฐ์ ธ์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์ฒดํํ๊ณ , ์์ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ์ง ์๊ธฐ๋ก ํ๋ค. django CSS ์ ์ฉ - ์์ธ : ์๋์ ๊ฐ์ ํ์์ผ๋ก style.css ํ์ผ์ ์ํฌํธํ์ฌ ์ฌ์ฉํ์๋ค. html ์ link ๋ฅผ ์ฌ์ฉํ์ง๋ง, ์ ์ฉ๋์ง ์์๋ค. CSS ๋ถํ - ํด๊ฒฐ : ๋ธ๋ผ์ฐ์ ์ ์บ์ ๋ฌธ์ ์๋ค. ์บ์๋ฅผ ์ ๋ฆฌํ๊ณ ๋๋ ์ ์ ์ฉ๋์๋ค. ๋ค์ ์ฌ์ฉํ ๋๋ ์๋ก์ด css ์ํฌํธ๊ฐ ๋์๋ค๋ฉด, ์บ์๋ฅผ ํ ๋ฒ ์ ๋ฆฌํ๊ณ ์๋ก๊ณ ์นจ์ ํ๊ฑฐ๋ ์บ์๊ฐ ๋์ ๋์ง ์๊ฒ ์ํฌ๋ฆฟ(ํผ๋ธ๋ฆญ) ๋ชจ๋๋ฅผ ์ด์ฉํ์. ๊ณต์ ํ๊ธฐ URL ๋ณต์ฌ์นด์นด์คํก ๊ณต์ ํ์ด์ค๋ถ ๊ณต์ ์์ค ๊ณต์ ๊ฒ์๊ธ ๊ด๋ฆฌ ๊ตฌ๋ ํ๊ธฐMOVEMENT.DEV Contents ์ฌ์ฉ์์ ์ํจ์์ค์ djangoCSS์ ์ฉ ๋น์ ์ด ์ข์ํ ๋งํ ์ฝํ ์ธ WIL_220508 2023.01.01 WIL_220501 2023.01.01 WIL_220424 2023.01.01 ๋๊ธ 0 + ์ด์ ๋๊ธ ๋๋ณด๊ธฐ