Software Study/통신
Jinja2 사용하기
욜스터
2021. 1. 15. 16:25
728x90
Jinja2는 Python 웹 프레임워크인 Flask에 내장되어 있는 Template엔진이다.
JSP와 비슷한 문법을 가지고 있다.
{{ ... }} : 변수나 표현식
{% ... %} : if나 for같은 제어문
{# ... #} : 주석
templates/index.html
<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> {% if title %} <title>{{ title }}</title> {% endif %} </head> <body> <h1>Bind string: {{ home_str }}</h1> <p>This page is for Flask tutorial.</p> <p>Bind list value: {{ home_list[2:4] }}</p> <ul> {% for idx in home_list %} <li>{{ idx }}</li> {% endfor %} </ul> </body> </html> |
app.py
from flask import Flask, render_template |
*<li> : list
728x90
반응형