下面的模板有问题: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 — 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/