R
R
Roman2020-08-14 14:07:32
Django
Roman, 2020-08-14 14:07:32

How to set up a style sheet for a web application written in django?

I am writing a site on django, I ran into a problem when designing the site using css. There is one application called "products". In the project directory, the html page template is located at products/templates/products/index.html, at the very beginning there is a css file connection in it:

{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'products/style.css' %}">
and there is also a div block with id = "area"
The css file itself is located in the project directory along the path products/static/products/style.css, its content looks like this:
body {
    background: white url("images/background.jpg") round;
  }
#area {
  color: black;
  font-size: 40px;
  }

I save all the files, run the manage.py file with the collectstatic option, and start the server
py manage.py collectstatic
py manage.py runserver

I start the server, the source code of the index.html file after applying the django templates looks like this:
<link rel="stylesheet" type="text/css" href="/static/products/style.css">


  <ul>
  
    <div id='area'><li><a href="/products/2">second test product!</a></li></div>
  
    <div id='area'><li><a href="/products/1">Test Product!</a></li></div>
  
  </ul>

but all the changes that I wrote in the style.css file are not displayed. If you follow the link "/static/products/style.css" from the index.html source code, style.css opens with the following content:
li a {
    color: green;
}

body {
    background: white url("images/background.jpg") round;
}
which is the previous content of the style sheet.
In general, the essence of the issue: I change the style sheet, run collectstatic and runserver, and the page does not change at all. What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2020-08-15
@tumbler

collectstatic collects the static of all connected applications (and libraries) into one folder, from where it should be given to nginx. runserver looks at the original static, not the collected one (otherwise even the admin panel would not work without collectstatic). Check where exactly the requested CSS file is given from: most likely, you are changing some other one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question