【问题标题】:Set Background image in CSS file using python flask framework render_template使用 python 烧瓶框架 render_template 在 CSS 文件中设置背景图像
【发布时间】:2020-11-29 05:20:42
【问题描述】:

我需要为我的 html 设置背景图片。我有一个文件系统 静态

  • CSS
  • img

这是我用来链接我的 css 文件的。

<link rel="stylesheet" href="{{ url_for('static',filename='css/index.css') }}">

在我的 css 文件中,我定义了背景图像

.bgimg-1 {background-image: url("/static/img/background.jpg");}

但是在我的烧瓶应用程序中,我收到了错误

127.0.0.1 - - [09/Aug/2020 19:10:04] "[37mGET / HTTP/1.1[0m" 200 -

127.0.0.1 - - [09/Aug/2020 19:10:04] "[33mGET /static/css/static/img/background.jpg HTTP/1.1[0m" 404 -

我不确定/static/css/ 来自哪里

我在<header class="bgimg-1 w3-display-container w3-grayscale-min" id="home">中定义了类

【问题讨论】:

    标签: python html css flask web-development-server


    【解决方案1】:

    我觉得,这是因为您的 index.css 文件位于 /static/css/ 文件夹中,并且从那里它指的是图像 (/static/img/background.jpg) ,所以将完整的图像网址设为此 - /static/css/static/img/background.jpg

    【讨论】:

    • 你建议如何解决这个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多