๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ’ชBackend/Django

Django๋กœ Pinterest ๋”ฐ๋ผ๋งŒ๋“ค๊ธฐ : ์„น์…˜ 1. Django Tutorial (8~10๊ฐ•)

#8 ์žฅ๊ณ  Template์˜ extends, include ๊ตฌ๋ฌธ๊ณผ render ํ•จ์ˆ˜

HTML์„ ์‚ฌ์šฉํ•œ ์žฅ๊ณ  ํ…œํ”Œ๋ฆฟ ์‚ฌ์šฉ๋ฒ•

HTML(Hyper Text Markup Language)

 

์ž์ฃผ ์“ฐ์ด๋Š” ๊ตฌ๋ฌธ

extends

  • pre-made, template,html ๋“ฑ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด ๋‘” ๋ธ”๋ก๋“ค์ด ์žˆ์„ ๋•Œ ์ฑ„์›Œ๋‚˜๊ฐ€๋Š” ๋Š๋‚Œ 
  • ๋ฐ”ํƒ•์„ ์ฑ„์›Œ๋‚˜๊ฐ€๋Š” ๋Š๋‚Œ

includes

  • ๋งŒ๋“ค๊ณ  ์žˆ๋Š” ํŒŒ์ผ๋“ค์ด ์žˆ์œผ๋ฉด ๊ทธ๊ฑธ ๋„ฃ์–ด์ฃผ๋Š” ๋Š๋‚Œ
  • ๋”๋ฏธ๋ฅผ ๊ฐ€์ ธ์™€์„œ ๊ฐ–๋‹ค๋ถ™์ด๋Š” ๋Š๋‚Œ

 

templates ์ƒ์„ฑ

ํ”„๋กœ์ ํŠธ ํŒŒ์ผ > templates ๋””๋ ‰ํ† ๋ฆฌ ์ƒ์„ฑ > base.html ์ƒ์„ฑ

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>TITLE</title></head><body></body></html>

๊ธฐ๋ณธ ์ฝ”๋“œ

 

์ด๊ฑฐ๋ฅผ views.py์—์„œ render๋กœ returnํ•˜๊ธฐ

def hello_world(request): return render(request,'base.html')

๋ฐ”๋กœ ์‹คํ–‰ํ•ด๋ณด๋ฉด ํ…œํ”Œ๋ฆฟ์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ๋œธ

⇒ settings.py์˜ TEMPLATES ๋ฆฌ์ŠคํŠธ์˜ DIRS ์ˆ˜์ • ํ•„์š”(ํด๋” ์ด๋ฆ„ ์ถ”๊ฐ€)

'DIRS': [os.path.join(BASE_DIR,'templates')],

๋‹ค์‹œ ์‹คํ–‰ํ•ด๋ณด๋ฉด TITLE ์ž˜ ๋œธ


 

#9 include/extends/block ๊ตฌ๋ฌธ์„ ์ด์šฉํ•œ ๋ผˆ๋Œ€ html ๋งŒ๋“ค๊ธฐ

๋ผˆ๋Œ€ ๋งŒ๋“ค๊ธฐ

head ๋ถ€๋ถ„ include๋กœ ๋ถ„๋ฆฌํ•˜๊ธฐ

head ํŒŒํŠธ head.html์— ๋บ€ ํ›„,

{%include 'head.html%}

๋กœ ์‚ฝ์ž…ํ•ด์ฃผ๊ธฐ

 

body ๋ถ€๋ถ„ div ๋ธ”๋ก ๋‚˜๋ˆ„๊ธฐ

์„ธ ๊ฐœ์˜ div ์ƒ์„ฑ ํ›„ ์Šคํƒ€์ผ ์ž…ํ˜€์ฃผ๊ธฐ (์ด๋•Œ, alt๋ฅผ ๋ˆ„๋ฅด๊ณ  ์ปค์„œ๋ฅผ ๋ˆ„๋ฅด๋ฉด ๋‹ค์ค‘ ์ž‘์—… ๊ฐ€๋Šฅ)

์ด๋Ÿฐ์‹์œผ๋กœ ๊ตฌํ˜„๋จ

 

header.html / block / footer.html ๋กœ ๊ตฌ๋ถ„

์œ„์™€ ๊ฐ™์ด ๊ตฌ๋ถ„ํ•˜๋ฉด block ๋งŒ ๋‹ค๋ฅธ ๋ฐ์—์„œ ๋ถˆ๋Ÿฌ์˜ฌ ๋•Œ ์ˆ˜์ • ๊ฐ€๋Šฅ

 

์ด๋Ÿฐ์‹์œผ๋กœ accountapp ๋‚ด์˜ hello_world.html์—์„œ content ๋ธ”๋ก ์•ˆ์— ๋“ค์–ด๊ฐˆ ๋‚ด์šฉ๋งŒ ์ˆ˜์ • (๋‚˜๋จธ์ง€(header,footer)๋Š” ์žฌ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ)

 

 

 


 

 

#10 style, ๊ตฌ๊ธ€ ํฐํŠธ๋ฅผ ํ†ตํ•ด Header, Footer ๊พธ๋ฏธ๊ธฐ

 

header ๊พธ๋ฏธ๊ธฐ

 

header ๊พธ๋ฏผ ํ›„ f12 (๊ฐœ๋ฐœ์ž๋ชจ๋“œ) ๋ฅผ ํ†ตํ•ด

์–ด๋–ป๊ฒŒ ๊ตฌ์„ฑ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ ๊ฐ€๋Šฅ

(์ฃผํ™ฉ์ƒ‰ : margin , ํŒŒ๋ž€์ƒ‰ : ์‹ค์ œ ๋‚ด์šฉ๋“ค)

 

elements ์—์„œ test-align ์„ ํ†ตํ•ด ์ •๋ ฌ ๊ธฐ์ค€ ์ˆ˜์ • ๊ฐ€๋Šฅ (์ผ์‹œ์ )

์˜๊ตฌ์ ์œผ๋กœ ์ ์šฉํ•˜๋ ค๋ฉด ํ•ด๋‹น ๋‚ด์šฉ์„ ๊ฐ์‹ธ๋Š” div์—์„œ style ์ฒ˜๋ฆฌํ•ด์ฃผ๊ธฐ

์ด์™ธ์—๋„ margin ๋“ฑ ์—ฌ๋Ÿฌ ์š”์†Œ๋“ค ์ˆ˜์ •~~

 

bootstrap ์ด์šฉํ•˜๊ธฐ

 

Get started with Bootstrap

 

Get started with Bootstrap

Bootstrap is a powerful, feature-packed frontend toolkit. Build anything—from prototype to production—in minutes.

getbootstrap.com

ํ•ด๋‹น ๋งํฌ ์ฐธ๊ณ ํ•ด์„œ head.html์— ์ถ”๊ฐ€ํ•˜๊ธฐ

 

 

ํฐํŠธ ์ž…ํžˆ๊ธฐ

 

๊ตฌ๊ธ€ ํฐํŠธ์—์„œ ๋งˆ์Œ์— ๋“œ๋Š” ํฐํŠธ ์ฐพ์€ ํ›„ select → ๋‚˜์˜ค๋Š” ๋งํฌ ๋ณต์‚ฌ ํ›„ head์— bootstrap์ฒ˜๋Ÿผ ๋ถ™์—ฌ๋„ฃ๊ธฐ

font-family: 'Vina Sans', sans-serif; ๋ฅผ ๋ณต์‚ฌํ•ด์„œ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์€ div์˜ ์Šคํƒ€์ผ์— ๋ถ™์—ฌ๋„ฃ์–ด์ฃผ๊ธฐ

 

์ด๋Ÿฐ์‹์œผ๋กœ ์ˆ˜์ •

 

 


 

๋ฐ•ํ™์„๋‹˜์˜ ์ธํ”„๋Ÿฐ ๊ฐ•์˜๋ฅผ ์ˆ˜๊ฐ•ํ•˜๋ฉฐ ์ •๋ฆฌํ•ด๋ณด๋Š” ๊ธ€์ž…๋‹ˆ๋‹ค.

https://www.inflearn.com/course/%EC%9E%A5%EA%B3%A0-%ED%95%80%ED%84%B0%EB%A0%88%EC%8A%A4%ED%8A%B8

 

์ž‘์ •ํ•˜๊ณ  ์žฅ๊ณ ! Django๋กœ Pinterest ๋”ฐ๋ผ๋งŒ๋“ค๊ธฐ : ๋ฐ”๋‹ฅ๋ถ€ํ„ฐ ๋ฐฐํฌ๊นŒ์ง€ ๊ฐ•์˜ - ์ธํ”„๋Ÿฐ

Python์˜ ๋Œ€ํ‘œ ์›น ํ”„๋ ˆ์ž„์›Œํฌ django๋ฅผ ์ด์šฉํ•ด Pinterest ํŠน์œ ์˜ ์นด๋“œํ˜• ๋ ˆ์ด์•„์›ƒ ๋””์ž์ธ์„ ๋ณธ๋”ด ์›น์„œ๋น„์Šค ๊ตฌํ˜„ํ•ด๋ด…๋‹ˆ๋‹ค., django, docker ์‹ค์ „ ๊ฐœ๋ฐœ์„ ํ†ตํ•ด ํ•œ ๋‹จ๊ณ„ ๋†’์€ ๊ฐœ๋ฐœ์ž๊ฐ€ ๋˜