WEB/python
[jinja2] 값 끼워넣기 / ㅇㅇ아 안녕 이라고 적었을때 ㅇㅇ에 값 끼워넣기
자바칩 프라푸치노
2021. 6. 9. 16:58
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>메인 페이지</h1>
<a href="/detail">상세 페이지로 가기</a>
<h3>{{ name }}아 안녕!</h3>
</body>
</html>
app.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def main():
myname = "sparta"
return render_template("index.html", name = myname)
@app.route('/detail')
def detail():
return render_template("detail.html")
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
main함수에서 myname변수에 sparta를 넣고 index.html을 만들때 name으로 같이 보내준다.
그리고 index.html에서는 name을 쓸수있는 것이다
진자 템플릿 언어로 {{}} 에 담아서 쓴다
728x90