【问题标题】:Why does bootstrap not show up when I run my website? [duplicate]为什么我运行我的网站时没有显示引导程序? [复制]
【发布时间】:2021-09-10 17:41:22
【问题描述】:

我是 Web 开发的新手,我正在使用 Flask 构建我的第一个网站。当我第一次运行该网站时,Bootstrap 无法正常工作,之后我进入了检查模式,它给了我一些错误。

我尝试清空缓存,但没有任何改变。

项目文件夹排列如下:

这是 HTML 代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/bootstrap.css">
    {% if title %}
    <title> Project--{{Title}} </title>
    {% else %}
    <title> Project </title>
    {%endif%}
</head>
<body>
    <div class="alert alert-primary" role="alert">
        Hello
      </div>
    <script src="js/bootstrap.js"></script>
</body>
</html>

python代码:

from flask import Flask,render_template,url_for
app=Flask(__name__,template_folder='Template')
@app.route("/")
def home():
    return render_template('Home.html',title='Home')

if __name__=='__main__':
    app.run(debug=True)

我该如何解决这个问题? 提前致谢!

【问题讨论】:

    标签: python html flask bootstrap-4


    【解决方案1】:

    您必须将 js 和 css 文件夹保存在一个名为 static 的文件夹中,该文件夹与您将只保留 html 文件的模板文件夹处于同一级别。

    您可以将href="{{ url_for('static', filename='css/bootstrap.css') }}" 用于名为 bootstrap.css 的 css 文件,该文件位于静态文件夹的 css 文件夹中。与我们的文件一样,src="{{ url_for('static', filename='js/bootstrap.js') }}"

    【讨论】:

      猜你喜欢
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-25
      • 2018-07-07
      • 2018-09-02
      • 2020-07-26
      • 2023-03-16
      相关资源
      最近更新 更多