# 경로 렌더링 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>
|
'PRACTICE > Basic' 카테고리의 다른 글
[Flask] url_for, redirect 사용하여 main, major, minor 페이지 출력 (0) | 2020.09.03 |
---|---|
[Flask] int, float값 구분하여 웹 페이지 호출 (0) | 2020.09.03 |
[Flask] escape, request 사용하여 웹에서 입력받은 값 출력 (0) | 2020.09.03 |
[C] %s, %c, null문자에 따른 출력값 비교 + 포인터변수에 배열주소를 저장하고 배열에 저장된 값 출력하기 (0) | 2020.08.24 |
[Arduino] 간단한 프린트문, 8개의 LED를 비트단위로 ON/OFF 하기 (0) | 2020.08.18 |
댓글