0

Template code

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

CSS code

li a {
    color: rgb(13, 238, 43);
}
body {
    background: rgba(240, 234, 234, 0.897) url("images/background.gif") no-repeat;
}

There is an background.gif in polls/static/images/background.gif

Except the background image, all the styles are presented correctly in the browser.

What might be the reasons? Thank you for your help!

Python Newbie
  • 317
  • 2
  • 9

1 Answers1

1

The url() CSS function is used to include a file. The parameter is an absolute URL, a relative URL, or a data URI

In your settings define STATIC_URL = '/static/', then url('/static/images/background.gif') will probably work or you can use url('{{ STATIC_URL }}images/background.git, note: no backslash after {{STATIC_URL}}

Read more here Difference between STATIC_ROOT and STATIC_URL

minglyu
  • 2,958
  • 2
  • 13
  • 32