flask: Python 으로 웹응용프로그램을 개발하기 위한 웹 프레임워크

jinja: Python 웹 프레임워크인 Flask에 내장되어 있는 Template 엔진(https://jinja.palletsprojects.com/en/2.10.x/)

 

  • test_Jinja.py

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')

@app.route('/index')

def index():

return render_template('index.html', title ='Flask Template Test', home_str = 'Hello Flask!', home_list = [1, 2, 3, 4, 5])

app.run(debug=True)

 

  • index.html

<!DOCTYPE html>

<html lang="ko">

<head>

<meta charset="UTF-8">

{% if title %}

<title>{{title}} </title>

{% endif %}

</head>

<body>

<h1>Bind String : {{home_str}}</h1>

<ul>

{% for idx in home_list %}

<li>{{idx}}</li>

{% endfor %}

</ul>

</body>

</html>

 

visual studio code에서 test_jinja.py 실행

+ Recent posts