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上找了很久,都没有结果,求大神救救俺
高洛峰2017-04-18 09:45:20
The reference in the template is a relative reference, and I didn’t specify itstatic
的路径, 当然还是404
, 所以用之前把static
目录位置source
Just hit static
路径写到PYTHONPATH
伊谢尔伦2017-04-18 09:45:20
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 directory
阿神2017-04-18 09:45:20
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?
@main.route('/test')
def test():
return render_template('test.html')
test.css is placed in the static/test folder
* {
color: red;
}
The html file is written here
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="{{url_for('static',filename='test/test.css')}}" >
</head>
<p>Test it</p>