jquery - Flask 无法加载 css 文件

标签 jquery python html css flask

下面的模板有问题:CSS 文件没有加载。

我将“style.css”正确地放置在“my_project/static/”中。

我刚刚尝试替换 <link rel=stylesheet ...>在带有“style.css”代码的 HTML 文件的源代码中,它可以工作。

问题是什么?

<!doctype html>
<title>{% block title %}Welcome{% endblock %} | MiniTwit</title>
<link rel=stylesheet type=text/css href="{{  url_for('static', filename='style.css') }}">

<div class=page>
  <h1>MiniTwit</h1>
  <div class=navigation>
  {% if g.user %}
    <a href="{{ url_for('timeline') }}">my timeline</a> |
    <a href="{{ url_for('public_timeline') }}">public timeline</a> |
    <a href="{{ url_for('logout') }}">sign out [{{ g.user.username }}]</a>
  {% else %}
<a href="{{ url_for('public_timeline') }}">public timeline</a> |
<a href="{{ url_for('register') }}">sign up</a> |
<a href="{{ url_for('login') }}">sign in</a>
  {% endif %}
  </div>
  {% with flashes = get_flashed_messages() %}
    {% if flashes %}
      <ul class=flashes>
      {% for message in flashes %}
        <li>{{ message }}
      {% endfor %}
      </ul>
    {% endif %}
  {% endwith %}
  <div class=body>
  {% block body %}{% endblock %}
  </div>
  <div class=footer>
    MiniTwit &mdash; A Flask Application
  </div>
</div>

最佳答案

您应该在 link 标签中将属性值用双引号引起来,并将此标签放在 head 标签内:

<head>
<title>{% block title %}Welcome{% endblock %} | MiniTwit</title>
<link rel="stylesheet" type="text/css" href="{{  url_for('static', filename='style.css') }}">
</head>

同时关闭 html 文件末尾的 html 标签。

关于jquery - Flask 无法加载 css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30853930/

相关文章:

jquery - Owl Carousel 在 IE8 和 IE9 中不起作用

Jquery Post - Itunes API 返回 200 和错误

javascript - on() 无法识别类

javascript - 如何只显示 Flot 图表的最后一点

python - 当客户端没有在Python中写任何内容(我只按Enter)时,如何从服务器验证变量

html - 填充改变表格内的宽度

javascript - 检测浏览器宽度并防止下载页面片段

javascript - 在另一个滚动函数中隐藏/显示滚动上的 div

python - 你真的可以使用 Visual Studio 2008 IDE 来编写 Python 代码吗?

python - FASTAPI测试数据库不创建数据库