模板渲染的使用

现在一般都是前后端分离开发了,模板相对较少使用。和django一样,flask也是支持模板渲染的。

flask中默认使用的是jinjia2模板渲染语言。

# template_folder:指定模板文件查找的目录(默认就是templates)

app = Flask(__name__, template_folder="templates")


使用模板渲染返回, 前面response笔记已经写过了

@app.route("/demo2")
def demo2():
    # 使用render_template渲染,可以传递上下文,这个和django是一样的
    # index.html是项目目录下的templates目录中寻找
    return render_template("index.html", username="张三")
posted @ 2023-10-04 12:17  蕝戀  阅读(6)  评论(0编辑  收藏  举报