python/Flask

jinja template

blackbearwow 2022. 5. 22. 13:11

flask에서 render_template함수를 사용해서 html을 렌더할 때, jinja템플릿을 사용한다.

https://jinja.palletsprojects.com/en/3.1.x/templates/

 

Template Designer Documentation — Jinja Documentation (3.1.x)

Template Designer Documentation This document describes the syntax and semantics of the template engine and will be most useful as reference to those creating Jinja templates. As the template engine is very flexible, the configuration from the application

jinja.palletsprojects.com

jsp에서 <%= %>, <% %>등의 태그가 있는것처럼 jinja템플릿에는 {% %}, {{ }}등의 태그가 있다.

  선언 표현식
statements {% ... %} 파이썬 문법이 사용된다. for를 사용하고는 endfor를 명시해주어야 하고 if를 사용한 후에는 endif를 명시해주어야 한다
expressions {{ ... }} 변수를 출력할 때 사용된다.
comments {# ... #} 주석이다.