-1

I launched the small Polls app from Django tutorial here: https://docs.djangoproject.com/en/4.1/intro/tutorial06/

The first time i wrote it, all worked fine. Then I tried to add the same style to all other html files in the same dir as index.html: results.hmtl, votes.html and detail.html and then the strangest thing happened. No styles were added to these files also when i tried to change the style of polls/static/polls/style.css , nothing happened. I even renamed the style.css and the styles added to index.html remained unchanged. This means django looks for styles elsewhere. So where is this place?

My settings are standard:

settings.py:

STATIC_URL = 'static/'
STATIC_ROOT = ""

index.html:

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

urls.py:

from django.conf import settings
from django.conf.urls.static import static

    urlpatterns = [
        path('polls/', include('polls.urls')),
        path('', include('polls.urls')),
        path('admin/', admin.site.urls)
    ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

No effect whatsoeveer. I read the documentation, read comments here, nothing flashes, so I'm asking here, hoping for a chance to repair my static. Thanks!

Update: The problem was my browser cache - I deleted it and everything is fine now. But this was a helpful lesson - I learned what paths does Django use, how to set and use them and that it does not keep cache by default.

  • Is it correct that on `index.html` page styles work fine? – Ivan Starostin Jun 04 '23 at 19:53
  • Please shot INSTALLED_APPS and django error log related to static files access attempts and/or http errors from chrome dev tools. – Ivan Starostin Jun 04 '23 at 19:54
  • `STATIC_ROOT = ""` is not something "standard". It is supposed to be a real path where `collectstatic` on later stages of development will deliver all the static files of your project for the following deployment to production server. – Ivan Starostin Jun 04 '23 at 19:55
  • index.html worked fine the first time i started the app. I wrote as in tutorial: ```li a { color: green; }``` then changed the color to purple and nothing happened. The same file, the same folder, the same css file. At that time I didn't write ```STATIC_ROOT = ""``` in settings.py, I tried to use it later. – Nikoi Nikoi Jun 05 '23 at 07:12

1 Answers1

0

Try with this setting but make sure static folder at root drictory

STATIC_URL = '/static/'
STATICFILES_DIRS = [BASE_DIR / 'static']

Directory Structure

- project directory
- app directory
- static directory
- manage.py
- db.sqlite3