Flask:模板渲染
本文章只作为个人笔记.
文章目录
前言
模板渲染
一、模板渲染
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def hello_world():
return render_template("index.html")
@app.route("/blog/<blog_id>")
def blog_detail(blog_id):
return render_template("blog_detail.html", blog_id=blog_id, username="笔写落去")
if __name__ == "__main__":
app.run(debug=True)
二、效果
使用render_template可以达到用html文件对网页进行渲染,可以传参数.
使用html收到变量,用{{变量名}}这样就能拿到变量的值了.
blog_detail.html渲染效果:
index.html渲染效果
原文地址:https://blog.csdn.net/qq_55383558/article/details/135462839
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!