Jinja
단순한 텍스트 파일로 모든 텍스트 기반 형식을 생성할 수 있음
파일 확장자에 관계없이 모든 파일을 템플릿으로 로드할 수 있음
템플릿을 식별하기 좋은 방법은 templates !
확장명에 관계없이 폴더에 있는 것. 대신 꼭 이름은 templates 로 !
- 템플릿 로드하는 법
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_templates("index.html")
- 기본 구분 기호
{% ... %} for 문
{{ ... }} 템플릿 출력으로 인쇄할 표현식의 경우
{# ... #} 템플릿 출력에 포함되지 않은 주석의 경우
# ... ## 라인문
- 기본사항을 보여주는 최소 형식
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Webpage</title>
</head>
<body>
<ul id="navigation">
{% for item in navigation %}
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
{% endfor %}
</ul>
<h1>My Webpage</h1>
{{ a_variable }}
{# a comment #}
</body>
</html>
- jinja 조건문( if / elif / else )
{% if users %}
<ul>
{% for user in users %}
<li>{{ user.username|e }}</li>
{% endfor %}
</ul>
{% endif %}
{% if kenny.sick %}
Kenny is sick.
{% elif kenny.dead %}
You killed Kenny! You bastard!!!
{% else %}
Kenny looks okay --- so far
{% endif %}
Jinja 에 대해 좀 더 알고싶다? 클릭 !
https://jinja.palletsprojects.com/en/2.11.x/templates/#line-statements
Template Designer Documentation — Jinja Documentation (2.11.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
반응형
'STUDY > Python' 카테고리의 다른 글
JWT(JSON Web Token) | 자격 증명 (0) | 2022.05.08 |
---|---|
쿠키&세션 | 둘의 차이점은? | HTTP의 비연결성 및 무상태성 특징을 보완한 기술 (0) | 2022.05.08 |
주말계획 | 5월 7일-5월 8일 | 인스타 클론코딩과 타임 어택 테스트를 치루고 공부해야겠다 싶은 것들 (0) | 2022.05.07 |
⏱타임어택 테스트, 제한시간 1시간의 결과는?!⏱ | 회원 가입 페이지를 만들고 Flask로 구현한 게시판 API 연동까지 ! | 5월 6일 (0) | 2022.05.07 |
DB설계를 위한 ERD 특강 | ERD Cloud? ☁️ | 거북이반🐢 | 이 곳은 이해가 쏙쏙 (0) | 2022.05.05 |