CSS 背景图像不显示在 Django 框架中

问题描述 投票:0回答:0

遵循 Django 中的 Polls Webapp 教程。通过我的命令行继续收到 404 错误,并显示我的图像图标,但不显示图像本身。

尝试多次更改路径,重置静态迁移并更改我的静态根目录。仍然没有图像。

这是我的 style.css

li a {
    color: green;
}

body {
    background-image: url('static/images/background.png') no-repeat;
}

这是我的 index.html

{% if latest_question_list %}
    <ul>
        {% for question in latest_question_list %}
        <li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a>
        </li>
    {% endfor %}
</ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}

{% load static %}

<link rel="stylesheet" href="{% static 'polls/style.css' %}">

<img src="{% static 'static/images/background.png' %}" alt="My Image">

这是我的一些设置.py

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


MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

有人有想法吗?

html css django background-image
© www.soinside.com 2019 - 2024. All rights reserved.