<分区>
<分区>
我正在尝试获取此 html 模板 - https://www.free-css.com/free-css-templates/page231/catalyst
解压缩后,文件夹包含 -
我知道我需要将 index.html 文件放在我的"template"文件夹中,将 css 文件放在我的“css”文件夹中,但我不知道将字体文件夹或图像文件夹放在哪里。我尝试了一些不同的方法,但最终还是得到了一个只有 html 的页面。
最佳答案
您应该将 index.html
放在 templates
文件夹中,将其他所有内容放在 static
文件夹中。
然后,在你的 application.py
中你可以使用:
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def index():
return render_template('index.html')
在 index.html
文件中,您可以使用 url_for 将所有链接作为该资源的路径。 方法:
<link rel=stylesheet type=text/css href="{{ url_for('static/css', filename='style.css') }}">
<link rel="stylesheet" href="{{ url_for('static/font-awesome/', filename='font-awesome.min.css') }}">
关于html - 如何在 Flask 中导入 html 模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52866132/