简体   繁体   English

CSS 文件(main.css)中的图像不会与 Flask 一起加载

[英]Images in CSS file(main.css) don't load with Flask

My folder layout is:我的文件夹布局是:

/env
   app.py
/env/static/styles
   main.css
/env/static/img
   contains all the image
/env/templates
   index.html

My main.css contains:我的 main.css 包含:

#background_section_top {
width: 100%;
height:88px;
background: url(static/img/background_section_top_bg.jpg);
background-repeat: repeat-x;
}

My index.html contains: <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles/main.css') }}">我的 index.html 包含: <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles/main.css') }}">

But I couldn't see the image in my index.html.但我在 index.html 中看不到图像。 Could you please help where I'm doing mistake?你能帮我在哪里做错吗? Thanks.谢谢。

Just modify只需修改

background: url(static/img/background_section_top_bg.jpg);

to

background: url(/static/img/background_section_top_bg.jpg);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM