본문 바로가기
PRACTICE/Basic

[Flask] 컬렉션(Dictionary), Jinja template(%) 사용하여 score table 출력

by 1005 2020. 9. 3.

< jinja template tutorial >

 

Template Designer Documentation — Jinja Documentation (2.11.x)

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 can be slightly different from t

jinja.palletsprojects.com

 

< Python Code >

 

1
2
3
4
5
6
7
8
9
10
from flask import Flask, render_template
app = Flask(__name__)
 
@app.route('/result')
def result():
   dict = {'phy':50,'che':60,'maths':70}
   return render_template('result.html', result = dict)
 
if __name__ == '__main__':
   app.run(host='0.0.0.0', port='80', debug = True)

 

< result.html >

 

1
2
3
4
5
6
7
8
9
10
11
12
13
<!doctype html>
<html>
   <body>
      <table border = 1>
         {% for key, value in result.items() %}
            <tr>
               <th> {{ key }} </th>
                 <td> {{ value }} </td>
            </tr>
         {% endfor %}
      </table>
   </body>
</html>
 

 

 

물리(physics), 화학(chemistry), 수학(math) 점수 출력

댓글