静态资源

from flask import Flask, render_template

app = Flask(__name__, template_folder="templates", static_folder="static", static_url_path="/static")

# template_folder:指定HTML文件查找目录
# static_folder:指定静态资源存放目录
# static_url_path:HTML中静态资源的标志

# 装饰器形式
# @app.route("/index")
# def index():
#     return render_template("index.html")

# 非装饰器形式
def index():
    return render_template('index.html')
app.add_url_rule('/index', 'index', index)

if __name__ == '__main__':
    app.run()
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
## 引用静态资源的两种方法,推荐第二种
<img src="/static/01.jpg"/>
  
<img src="{{ url_for('static',filename='01.jpg')}}" />
</body>
</html>

相关文章:

  • 2021-07-03
  • 2021-12-26
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
  • 2021-05-16
猜你喜欢
  • 2022-12-23
  • 2021-11-14
  • 2021-08-30
  • 2021-11-07
  • 2022-12-23
  • 2021-11-30
  • 2021-09-09
相关资源
相似解决方案