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

Django静态图片无法加载但CSS正常加载的问题求助

Django静态图片无法加载但CSS正常加载的问题求助

最近用Django做项目时遇到个奇怪的情况:静态目录里的CSS文件能正常加载,但同样路径下的图片就是显示不出来,有没有大佬能帮我看看问题出在哪呀?

我的HTML页面代码

<!DOCTYPE html>
<html lang="en">
{% load static %}
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="{% static 'home.css' %}" type="text/css" rel="stylesheet">
    <title>Hello World</title>
</head>
<body>
    <h1>Home</h1>
    <img href="{% static 'icons/folder.png' %}" alt="folder">
    {% for file in files %}
        {% if file.1 == True %}
            <p><a href="/files/home/{{file.2}}">{{file}}></a></p>
        {% else %}
            <p>{{file}}</p>
        {% endif %}
    {% endfor %}
</body>
</html>

settings.py中的静态文件配置

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

我的项目目录结构

项目根目录下有个static文件夹:

  • 直接在static里放了home.css文件
  • static下还有个icons子文件夹,folder.png图片就存在这里

现在CSS样式能正常生效,但图片就是加载不出来,我是不是哪里配置或者代码写错了?如果需要其他信息的话,我随时补充~

备注:内容来源于stack exchange,提问作者Dinosaur

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 08:43:00