데이터 표현을 제어하는 도구이자 표현에 관련된 로직
# app/views.py
from django.shortcuts import render
# Create your views here.
def index(request):
context = {
'name' : 'Hangyeol',
'age' : 21,
}
print('>>>')
print(context)
return render(request, 'articles/index.html', {'context':context})
<!--app/templates/app/index.html-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Hola! {{context.name}} </h1>
<h2>나이는 : {{context.age}} </h2>
</body>
</html>
{{context.name}}
<h2>나이는 : {{context.age | add:2}} </h2>
{% tag %}
{% if %}{% end if %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Hola! {{context.name}} </h1>
{% if context.age == 21 %}
<p>스물하나 부럽다</p>
{% endif %}
<h2>나이는 : {{context.age}} </h2>
</body>
</html>
context.age == 27
이면 if tag에 의해 "스물하나 부럽다"가 안나올 것이다
{# #}