ํ ํ๋ฆฟ ์ธ์ด
ํ ํ๋ฆฟ ์ธ์ด๋ ํ์ด์ฌ ๋ณ์์ ๋ฌธ๋ฒ์ html ์์์ ์ธ ์ ์๋๋ก ์ฅ๊ณ ์์ ์ ๊ณตํ๋ ์ธ์ด์ ๋๋ค.
๋ณ์
{{ ๋ณ์ }}
๋ณ์๋ {{ ๋ณ์ }} ๋ก ์ฌ์ฉ ๋ฉ๋๋ค.
ํ ํ๋ฆฟ ์์ง์ด ๋ณ์๋ฅผ ๋ง๋๋ฉด, ํ๊ฐํ์ฌ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ์นํํฉ๋๋ค.
๋ณ์๋ช ์ ๋ฐ์ค("_")๊ณผ ์๋ฌธ์ผ๋ก ์ด๋ค์ง๋ฉฐ ๊ณต๋ฐฑ์ด๋ ํน์๋ฌธ์๋ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๋ณ์๋ช ์์ ์ (".")์ ๊ธฐ์ ์ ์ผ๋ก ๋ณ์์ ์์ฑ์ ์ ๊ทผํ ๋ ์ฌ์ฉ๋ฉ๋๋ค.
{{ section.title }}
์ด ๊ฒฝ์ฐ section ๊ฐ์ฒด์ title ์์ฑ์ผ๋ก ์นํ๋ฉ๋๋ค.
ํํฐ
ํํฐ๋ฅผ ์ฌ์ฉํจ์ผ๋ก์จ ๋ณ์์ ํ์์ ๋ณํ๋ฅผ ์ค ์ ์์ต๋๋ค.
{{ ๋ณ์๋ช
| ๋ด์ฅ ํํฐ }}
๋ณ์์ ๊ธธ์ด๋ฅผ ๋ฐํํ๊ฑฐ๋, ๋ณ์์ ์์ n๊ฐ์ ๋จ์ด๋ง ๋ฐํํ๊ฑฐ๋, ๋ณ์๋ฅผ ๋ชจ๋ ์๋ฌธ์๋ก ๋ณ๊ฒฝํ๊ฑฐ๋ ๋ฑ์
์ฌ๋ฌ๊ฐ์ง ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค.
{{ name|lower }} # {{ name }}๋ณ์์ lower ํํฐ๋ฅผ ์ ์ฉํ์ฌ ํ
์คํธ๋ฅผ ์๋ฌธ์๋ก ๋ณ๊ฒฝ์ํจ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅ.
{{ name|length }} # {{ name }}๋ณ์์ ๊ฐ์ ๊ธธ์ด๋ฅผ ๋ฐํํฉ๋๋ค.
{{ name|striptags }} # {{ name }}๋ณ์์ ํฌํจ๋ HTML ํ๊ทธ๋ฅผ ์ ๊ฑฐํฉ๋๋ค.
ํ๊ทธ
Django์์๋ ์ค๋ฌด๊ฐ๊ฐ ๋๋ ํ ํ๋ฆฟ ํ๊ทธ๊ฐ ๋ด์ฅ๋์ด ์์ต๋๋ค.
ํ ํ๋ฆฟ ํ๊ทธ์ ์ข ๋ฅ์๋ ๋ฐ๋ณต๋ฌธ, ์กฐ๊ฑด๋ฌธ, ์์ ๋ฑ์ด ์์ต๋๋ค.
{% ํ๊ทธ %}
ํ๊ทธ๋ {% ํ๊ทธ %} ํํ๋ก ์ฌ์ฉํฉ๋๋ค.
if ํ๊ทธ
{% if latest_question_list %}
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
{% else %}
<p>No latest_question_list are available.</p>
{% endif %}
latest_question_list ์ด ์กด์ฌํ ๊ฒฝ์ฐ
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li> ๋ฅผ ์ถ๋ ฅํ๊ณ
์กด์ฌํ์ง ์์ ๊ฒฝ์ฐ <p>No polls are available.</p>๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
๋ํ if ํ๊ทธ์ ๊ฐ์ข ์ฐ์ฐ์๋ ์ฌ์ฉํ ์ ์์ต๋๋ค.
{% if latest_question_list|length > 5 %}
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
{% else %}
<p>No latest_question_list are available.</p>
{% endif %}
๋ฐ๋ณต๋ฌธ
{% for question in latest_question_list %}
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
{% endfor %}
for ํ๊ทธ๋ endfor๋ก ๋์ ์๋ฆฝ๋๋ค.
'Web > ๐ Django' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Django ํํ ๋ฆฌ์ผ (4) (0) | 2020.06.10 |
---|---|
Django ํํ ๋ฆฌ์ผ (3) (0) | 2020.06.09 |
Django ํํ ๋ฆฌ์ผ (2) (0) | 2020.06.09 |
Django ํํ ๋ฆฌ์ผ (1) (0) | 2020.06.09 |