Skip to main content
 首页 » 编程设计

python之Flask 和 css 引用静态文件

2025年05月04日13JustinYoung

我有一个基本的 flask 应用程序,我在我的 css 文件中引用背景图像,就像这样

.three { 
  background:url('/static/images/house.jpg'); 
} 

我的文件夹组织是这样的:

project 
    app.py 
    -static 
        -images 
            house.jpg 
        -css 
            index.css 
    -templates 
        index.html 

如何让我的 css 正确调用图像?

请您参考如下方法:

将您的 css 更改为此,然后重试:

.three { 
  background-image: url('images/house.jpg'); 
}