Flask

[Flask] 경로 랜더링 render_template

땅콩새싹 2020. 9. 24. 09:51
반응형

경로 랜더링 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>

 

실행 모습

 

반응형