flask 起的本地服务,static 文件夹里面的css 一直是404
template 里面引用的代码如下:
{% block head %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/base.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/cms.css') }}">
{% endblock %}
目录如下:
报错如下:
so上找了很久,都没有结果,求大神救救俺
The reference in the template is a relative reference, and I didn’t specify it
static
的路径, 当然还是404
, 所以用之前把static
目录位置source
Just hit
static
路径写到PYTHONPATH
Your root directory should not be the app, it should be the level above the app.
url_for
It is static in the project root directoryurl_for added _external=True is an absolute reference.
I programmed a routing test myself and found no such problem...
Have you posted the other codes in the HTML to take a look
Also I would like to ask, if the poster puts the css file in the static folder, will it run successfully?
test.css is placed in the static/test folder
The html file is written here