Django๐Ÿญ 5

Template ์—ฐ๊ฒฐํ•˜๊ธฐ๐ŸŽ

์•ฑ ๋ ˆ๋ฒจ์˜ templates ํด๋” ๋‚ด๋ถ€์˜ html ํŒŒ์ผ์„ view์™€ ์—ฐ๊ฒฐํ•˜๊ธฐ(์ •ํ™•ํ•œ ์œ„์น˜๋Š” templates/์•ฑ์ด๋ฆ„/example.html) Steps๐Ÿ˜: 1) Create project with django-admin startproject my_site Create App Directory with python manage.py startapp my_app command. Create the relevant URLs and Views(์•ฑ ๋ ˆ๋ฒจ์˜ urls.py๋Š” ์ž๋™ ์ƒ์„ฑ๋˜์ง€ ์•Š์Œ). Map the App URLs to the Project URLs. 2) python manage.py migrate : settings.py ๋‚ด๋ถ€์˜ ์„ค์น˜๋œ ์•ฑ์„ ๋ณด๊ณ , ํ•„์š”ํ•œ db ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•จ. 3) Inside o..

Django๐Ÿญ 2022.06.28

Dynamic View and logic(๋™์  ๋ทฐ์™€ ๋กœ์ง)๐Ÿ˜‹

๐Ÿ’ก๋™์  ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ path converter๋กœ ์ „๋‹ฌํ•˜์—ฌ view์™€ urlpatterns์„ ๋™์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ ํ•œ๋‹ค. 1๏ธโƒฃnews_view์—์„œ url๋กœ topic์„ ๋ฐ›์•„ topic์— ๋งž๋Š” ํŽ˜์ด์ง€๋ฅผ ๋ฆฌํ„ดํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“ค์–ด ๋ณด๋ คํ•จ. 2๏ธโƒฃadd_view์—์„œ url๋กœ ๋‘ ์ˆซ์ž๋ฅผ ์ „๋‹ฌ ๋ฐ›์•„ ๋‘ ์ˆ˜์˜ ํ•ฉ์„ ๋ฆฌํ„ดํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“ค์–ด ๋ณด๋ คํ•จ. #my_site > my_app > views.py from django.shortcuts import render from django.http.response import HttpResponse # Create your views here. articles = { 'sports':'Sports Page', 'finance':'Finance Page', 'politics':'..

Django๐Ÿญ 2022.06.27

์žฅ๊ณ  ํ”„๋กœ์ ํŠธ ์‹œ์ž‘ํ•˜๊ธฐ(ํ”„๋กœ์ ํŠธ, ์•ฑ ๋งŒ๋“ค๊ธฐ)๐Ÿ’ก

VS-code ํ„ฐ๋ฏธ๋„์— ์ž…๋ ฅ 1๏ธโƒฃ์žฅ๊ณ  ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ django-admin startproject my_site : 'my_site'๋ผ๋Š” ์ด๋ฆ„์˜ ์žฅ๊ณ  ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ์•„๋ž˜์™€ ๊ฐ™์€ ํด๋” ์ƒ์„ฑ - my_site #๋ฃจํŠธ ๋””๋ ‰ํ„ฐ๋ฆฌ(ํ”„๋กœ์ ํŠธ ์ปจํ…Œ์ด๋„ˆ) - my_site - __init__.py #Python์—๊ฒŒ ์ด ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ PythonํŒจํ‚ค์ง€๋กœ ๊ฐ„์ฃผํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ ์•Œ๋ ค์คŒ. - settings.py #ํ”„๋กœ์ ํŠธ ์„ค์ • ๋ฐ ๊ตฌ์„ฑ ํŒŒ์ผ - urls.py #๋ณธ์งˆ์ ์œผ๋กœ ์›น์‚ฌ์ดํŠธ๋ฅผ ํ†ตํ•ด ๋ทฐ๋ฅผ ๊ฐ€๋ฆฌํ‚ฌ ๋•Œ ์ž‘๋™ํ•œ๋‹ค. - asgi.py #ASGI ํ˜ธํ™˜ ์›น ์„œ๋ฒ„๋ฅผ ํ”„๋กœ์ ํŠธ์— ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•œ ์—”ํŠธ๋ฆฌ ํฌ์ธํŠธ - wsgi.py #WSI ํ˜ธํ™˜ ์›น ์„œ๋ฒ„๋ฅผ ํ”„๋กœ์ ํŠธ์— ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•œ ์—”ํŠธ๋ฆฌ ํฌ์ธํŠธ - manage.py #Django ํ”„๋กœ์ ํŠธ์™€ ์ƒ..

Django๐Ÿญ 2022.06.27

View์™€ URL ์—ฐ๊ฒฐํ•˜๊ธฐ๐Ÿคช

Views : what information is being shown to the client URLs : where that information is shown on the website They work in concert so you can think of each View/URL pairing as a web page on the website. โœ…How to connect a View to a URL โžก path() ํ•จ์ˆ˜ ์‚ฌ์šฉํ•ด์„œ! ๋งค๊ฐœ๋ณ€์ˆ˜ : - route : String code the contains the URL pattern. Django will scan the relevant urlpatterns list until it finds a matching string route - ..

Django๐Ÿญ 2022.06.27