반응형
경로 랜더링 render_template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# 경로 랜더링 render_template
# 꼭 templates 폴더를 만들어 주어야 합니다.
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
val = [1,2,3,4,5]
return render_template('hello.html', title = '제목', val=val)
# templates폴더 안의 'hello.html'을 참조합니다.
if __name__ == '__main__':
app.run(host='0.0.0.0', port='80',debug = True)
|
<exam02.py>
실행하는 exam02.py경로에 templates폴더를 만들어 주고 templates안에 참조하고 싶은 html을 만들어 줍니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>
안녕하세요
</h1>
포뇨
<br>
소스케<br>
{{title}} <!--제목-->
{{val}} <!--[1,2,3,4,5]-->
</body>
</html>
|
<hello.html>
반응형
'Flask' 카테고리의 다른 글
[Flask] url_for, render_template를 이용해 LOGIN BOX CSS 적용하기 + Bootstrap (4) | 2020.09.24 |
---|---|
[Flask] url_for, render_template를 이용해 이미지 출력하기 (0) | 2020.09.24 |
[Flask] escape, request 활용 (0) | 2020.09.24 |
[Flask] redirect, url_for 활용 (0) | 2020.09.24 |
[Flask] 플라스크 환경 구성 (using Anaconda, Visual Studio Code) (0) | 2020.09.23 |