python flask 静态资源404问题
ringa_lee
ringa_lee 2017-04-18 09:43:20
0
4
942

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上找了很久,都没有结果,求大神救救俺

ringa_lee
ringa_lee

ringa_lee

reply all(4)
小葫芦

The reference in the template is a relative reference, and I didn’t specify itstatic的路径, 当然还是404, 所以用之前把static目录位置source

Just hit static路径写到PYTHONPATH

伊谢尔伦

Your root directory should not be the app, it should be the level above the app. url_forIt is static in the project root directory

Ty80

url_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?

@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>

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!