You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django中无法显示/static/img/background.jpg背景图片求助

背景图无法显示的问题排查与修复

核心问题及修复方案

  • 模板语法错误:你的.start类中background-image的静态资源标签闭合错误,误将%}写成了%],导致服务器无法正确解析图片路径。修正后路径应为:
    background-image: url("{% static 'img/background.jpg' %}");
    
  • 图片后缀笔误:虽然不影响背景图加载,但你的<img>标签里src属性使用了错误的后缀.img,正确应为.jpg,建议同步修正。
  • Header样式无关性:你的header样式未设置position: fixed,属于正常文档流元素,不会遮挡下方的.start容器,因此背景图不显示与header样式无关。

修正后的完整代码片段

<style>
  .start {
    background-image: url("{% static 'img/background.jpg' %}");
    background-color: #cccccc;
    height: 500px;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    position: relative;
  }
</style>

<div class="start">
    <img src="{% static 'img/background.jpg' %}" alt="background">
    <h1>DO YOU WANT TO GET BETTER?</h1>
</div>

内容的提问来源于stack exchange,提问作者PHILLIPP APETENOK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 02:47:17