- λμ μΉ νμ΄μ§ ꡬμ±μ μν΄ Template κ°λ
μ νμ©ν©λλ€.
indexTemplate = loader.get_template('Index.html')
return HttpResponse(indexTemplate.render())
- μ£Όμ
<!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>
{# μ΄ λΆλΆμ μ£Όμμ
λλ€. #}
{% comment %}
μ΄ λΆλΆμ
μ¬λ¬ μ€
μ£Όμμ
λλ€.
{% endcomment %}
</body>
</html>
- views.py Code
indexTemplate = loader.get_template('Index.html')
title = "μλ
νμΈμ Django μ
λλ€"
render_data = {
'title' : title
}
return HttpResponse(indexTemplate.render(render_data, request))
- λ³μ μΆλ ₯
<!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>
{# μ΄ λΆλΆμ μ£Όμμ
λλ€. #}
{% comment %}
μ΄ λΆλΆμ
μ¬λ¬ μ€
μ£Όμμ
λλ€.
{% endcomment %}
<h1>{{title}}</h1>
{% λ³μ μΆλ ₯ %}
{% with discription="λ°κ°μ΅λλ€" %}
<h3>{{discription}}</h3>
{% endwith %}
</body>
</html>
- if-else문
<!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>
{# μ΄ λΆλΆμ μ£Όμμ
λλ€. #}
{% comment %}
μ΄ λΆλΆμ
μ¬λ¬ μ€
μ£Όμμ
λλ€.
{% endcomment %}
<h1>{{title}}</h1>
{# λ³μ μΆλ ₯ #}
{% with discription="λ°κ°μ΅λλ€" %}
<h3>{{discription}}</h3>
{% endwith %}
{% if a1 == 10 %}
<h3>h1μ 10μ
λλ€.</h3>
{% elif a1 == 5 %}
<h3>a1μ 5μ
λλ€</h3>
{% elif a1 == 10 %}
<h3>a1μ 10μλλ€.</h3>
{% else %}
<h3>a1μ 20μ΄ μλλλ€</h3>
{% endif %}
</body>
</html>
- forλ¬Έ λ° cycle
<!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>
{# μ΄ λΆλΆμ μ£Όμμ
λλ€. #}
{% comment %}
μ΄ λΆλΆμ
μ¬λ¬ μ€
μ£Όμμ
λλ€.
{% endcomment %}
{% comment %}
<h1>{{title}}</h1>
{% endcomment %}
{# λ³μ μΆλ ₯ #}
{% with discription="λ°κ°μ΅λλ€" %}
<h3>{{discription}}</h3>
{% endwith %}
{% if a1 == 10 %}
<h3>h1μ 10μ
λλ€.</h3>
{% elif a1 == 5 %}
<h3>a1μ 5μ
λλ€</h3>
{% elif a1 == 10 %}
<h3>a1μ 10μλλ€.</h3>
{% else %}
<h3>a1μ 20μ΄ μλλλ€</h3>
{% endif %}
<hr/>
{% for m in members %}
{{m.id}}<br/>
{{m.firstname}}<br/>
{{m.lastname}}<br/>
<hr/>
{% endfor %}
{% for m in members%}
<div>
{{m.id}}><br/>
{{m.firstname}}<br/>
{{m.lastname}}<br/>
</dvie>
<hr/>
{% endfor%}
</body>
</html>