【问题标题】:Flask with css doesnt seem to be working properly带有 css 的烧瓶似乎无法正常工作
【发布时间】:2021-09-19 14:37:27
【问题描述】:

对不起,如果这有点含糊。我一直在尝试使用构建一个简单的表。我一直在关注this tutorial,但是当我运行该站点时,css 似乎不起作用。某些部分可以,例如行着色,但仅此而已。有点奇怪,希望你们中的一个可以帮助我。

HTML:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Mankey Activity</title>
    <link rel="stylesheet" href="/static/styles.css"/>
  </head>
  <body>
    <table class="table">
      <tr class="table__header">
        {% for header in headings %}
        <th class="table__cell>">{{ header }}</th>
        {% endfor %}
      </tr>
      {% for row in data %}
      <tr class="table__row">
        {% for cell in row %}
        <td class="table__cell">{{ cell }}</td>
        {% endfor %}
      </tr>
      {% endfor %}
    </table>
  </body>
</html>

CSS:

.table {
  border-spacing: 0;
  border-radius: 4;
  margin: 1rem;
  background-color: #f5f5f5;
}

.table__row:nth-child(even) {
  background-color: #e5e5e5;
}

.table__header {
  text-align: left;
}


.table__cell {
  padding: 8px;
  text-align: left;
}

网站:

对不起,如果我是愚蠢的。

【问题讨论】:

    标签: html css flask


    【解决方案1】:

    尝试用 &lt;link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}"&gt; 替换此行:&lt;link rel="stylesheet" href="/static/styles.css"/&gt;

    【讨论】:

    • 应该提到我试过了。自从您发表评论以来,仔细检查了一遍,仍然无效。结果相同。
    • 你能分享一下你的项目结构吗
    • 检查服务器日志中是否有404错误,比如styles.css not found, 404 error。如果出现 404 错误,则应用程序无法找到您的 CSS 文件。 ELSE 清除缓存,或进行硬刷新(右键单击谷歌浏览器上的重新加载按钮并选择硬重新加载)
    • 我的错,我很愚蠢。需要清除缓存(由于某种原因两次)。对不起!
    猜你喜欢
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 2022-01-23
    • 2017-09-04
    • 2012-05-06
    • 2013-02-17
    • 2017-10-09
    相关资源
    最近更新 更多