切换主题
一、模板的基本使用
一、渲染模板
1、基础使用
在templates文件夹index.html
python
from flask import render_template
@app.route("/")
def index():
return render_template("index.html")
2、修改模板文件的查找地址
template_folder指定模板文件的具体路径
python
app=Flask(__name__,template_folder=r"D:\templates")
二、渲染变量
1、传递参数到HTML文件
python
@app.route("/variable")
def variable():
hobby="游戏"
return render_template("variable.html",hobby=hobby)
2、渲染参数
html
<h1>我的爱好是{{hobby}}</h1>