작정하고 장고 8강 - 장고 Template extends include 구문, render : Django로 Pinterest 따라하기!
#in accountapp/views.py
from django.shortcuts import render
def hello_world(request):
return render(request, 'base.html')
#in mysite/settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(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',
],
},
},
]
<div style="height: 10rem; background-color: #38df81; border-radius: 1rem; margin: 2rem; ">
</div>
<body>
{% include 'header.html' %}
<div style="height: 20rem; background-color: #38df81; border-radius: 1rem; margin: 2rem; ">
</div>
{% include 'footer.html' %}
</body>
<body>
{% include 'header.html' %}
{% block content %}
{% endblock %}
{% include 'footer.html' %}
</body>
{% extends 'base.html'}
{% block content %}
<div style="height: 20rem; background-color: #38df81; border-radius: 1rem; margin: 2rem; ">
<h1>testing</h1>
</div>
{% endblock %}
def hello_world(request):
return render(request, 'accoutapp/hello_world.html')
base.html
<!DOCTYPE html>
<html lang="ko">
{% include "head.html" %}
<body>
{% include 'header.html' %}
<hr>
{% block content %}
{% endblock %}
<hr>
{% include 'footer.html' %}
</body>
</html>
header.html
<div style="text-align: center; margin: 2rem 0;">
<div>
<h1>My site</h1>
</div>
<div>
<span>nav1</span>
<span>nav2</span>
<span>nav3</span>
<span>nav4</span>
</div>
</div>
footer.html
<div style="text-align: center; margin-top: 2rem;">
<div style="font-size: .6rem;">
<span>공지사항</span> |
<span>제휴문의</span> |
<span>서비스 소개</span>
</div>
<div style="margin-top: 1rem;">
<h6 style="margin-top: 1rem;">My site</h6>
</div>
</div>
<head>
<meta charset="UTF=8">
<title>title</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
</head>
<head>
<meta charset="UTF=8">
<title>title</title>
<!-- bootstrap link -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Zen+Dots&display=swap" rel="stylesheet">
</head>
header.html
<div style="text-align: center; margin: 2rem 0;">
<div>
<h1 style="font-family: 'Zen Dots'; cursive;">My site</h1>
</div>
<div>
<span>nav1</span>
<span>nav2</span>
<span>nav3</span>
<span>nav4</span>
</div>
</div>
footer.html
<div style="text-align: center; margin-top: 2rem;">
<div style="font-size: .6rem;">
<span>공지사항</span> |
<span>제휴문의</span> |
<span>서비스 소개</span>
</div>
<div style="margin-top: 1rem;">
<h6 style="margin-top: 1rem; font-family: 'Zen Dots'; cursive;">My site</h6>
</div>
</div>