【问题标题】:Using Flask: bootstrap works but custom stylesheet doesnt't使用 Flask:引导程序有效,但自定义样式表无效
【发布时间】:2020-08-14 07:35:24
【问题描述】:

我检查了其他主题,它们看起来很相似,但不能解决我的问题: 我正在使用烧瓶和引导程序编写一个 Web 应用程序,但我的自定义样式表被完全忽略了,我不知道为什么。

  <head>
      <!-- Required meta tags -->
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
      <link href="/static/styles.css" rel="stylesheet">
      <title>C$50 Final_Project: {% block title %}{% endblock %}</title>    
  </head>

【问题讨论】:

  • 这意味着您的 CSS 文件未正确加载。尝试像你一样指定相对路径而不是绝对路径> /static/styles.css -> static/style.css。
  • 不会改变任何东西。当我点击我的原始链接时,它最终会出现在它应该在的位置。如果我将其更改为您的建议,我会收到错误,即它不存在。不过谢谢。
  • 检查您的浏览器控制台,错误和警告是什么?

标签: css flask


【解决方案1】:

改用 Compiled CSS 和 JS?

https://getbootstrap.com/docs/4.3/getting-started/download/

也许尝试使用“url_for”作为文件路径 &lt;link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='bootstrap/bootstrap.min.css') }}"&gt;

【讨论】:

【解决方案2】:

需要清除浏览器缓存...

我不知道为什么这个问题被否决了这么多,但我可能应该补充一点,static.css 的路径不是问题...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-19
    • 1970-01-01
    • 2017-09-15
    • 2015-08-07
    • 2019-09-18
    • 2014-05-03
    • 1970-01-01
    • 2012-09-27
    相关资源
    最近更新 更多