python - Django 投票应用程序 : Background Image Not Loading

标签 python html css django

我正在学习 Django 并构建第一个测试投票应用程序,但遇到了背景图像问题。绿色文本有效,但添加背景图像没有任何作用(背景只是白色)。知道为什么这不能正常工作吗?

背景图片C:\Users\xxx\Python\Django\mysite\polls\static\polls\images\sample123.jpg

CSS样式:C:\Users\xxx\Python\Django\mysite\polls\static\polls\style.css

li a {
    color: blue;
}

body {
        background: url('C:\Users\xxx\Python\Django\mysite\polls\static\polls\images\sample123.jpg');
        background-repeat: no-repeat;
         }

索引 HTML:C:\Users\xxxx\Python\Django\mysite\polls\templates\polls

{% load static %}

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

{% 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 %}

最佳答案

这应该可以解决问题

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

关于python - Django 投票应用程序 : Background Image Not Loading,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65402732/

相关文章:

python - 关于 BeautifulSoup 中 get_text() 的建议

python - python 中的特征选择

jquery - 每行内容包裹在一个 div 中

php - <a href="#!/home> 有什么用?

css - 使用 CSS3 的饼图

python - 测试正在安装的 Python 模块依赖项

Python/BeautifulSoup - 在同一标签/元素中获取特定属性

javascript - 如何将textarea数据保存到html文件中?

html - 为什么我的边距在 Chrome 中看起来与在所有其他浏览器中不同

html - CSS 中的 Concat 标签