PRACTICE/Basic
[Flask] render_template 사용하여 count 출력
1005
2020. 9. 3. 17:41
# 경로 렌더링 render_template
# 꼭 templates 폴더를 만들어 주어야 함.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
from flask import Flask, render_template
app = Flask(__name__)
cnt = 0 #전역변수
@app.route('/')
def count():
global cnt #전역변수를 함수 내에서 사용하기 위해 global 붙여줌.
cnt += 1
return render_template('count.html',cnt = cnt)
if __name__ == '__main__':
app.run(host='0.0.0.0',debug=True, port='80')
|
< count.html >
1
2
3
4
5
|
<html>
<body>
<h1>Visit Count: {{cnt}}</h1>
</body>
</html>
|