先要在 app-flask 目录下创建 templates 文件夹,目录树如下,
app-flask
|--venv
|--templates
|--hello.py
在 templates 路径下新建 index.html 主页,随便写点内容,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>app-flask</title>
</head>
<body>
<div class="wrapper">
hello, world
</div>
</body>
</html>
然后,剩下的工作就都是 hello.py 的啦,在 .py 中配置好路由,
@app.route('/', methods=['GET', 'POST'])
def index():
return render_template('index.html')
其中的 render_template()
用于网页渲染,需要导包,
# 用于显示 H5 静态页面
from flask import render_template