Check Your path again,
If it's correct Follow the Guidelines to Include CSS in Django Project

Static files are intended to wrap CSS files and your images, Django automatically identifies this file.

  1. Create static folder in your app folder, same directory as of migrations and template folder
  2. Create css Folder and insert it into static Folder
  3. Now put your styles.css into css folder
  4. Now in your HTML File where you want to include CSS, add {% load static %} On the top of HTML File and Your Path should be like this <link rel="stylesheet" href="{% static 'css/styles.css' %}"> in HTML file.
  5. Then Make Change To Your settings.py in projectfoldername with-

    STATIC_URL = '/static/'

    STATICFILES_DIRS = [ os.path.join(BASE_DIR,'static') ]

    STATIC_ROOT = os.path.join(BASE_DIR, 'assets')

Then Run this command

python manage.py collectstatic

You static file will be copied to New file created by django as assets.

If it does not reflect changes Refer here If it does not work

Answer from Prabhat Singh on Stack Overflow
Top answer
1 of 2
20

Check Your path again,
If it's correct Follow the Guidelines to Include CSS in Django Project

Static files are intended to wrap CSS files and your images, Django automatically identifies this file.

  1. Create static folder in your app folder, same directory as of migrations and template folder
  2. Create css Folder and insert it into static Folder
  3. Now put your styles.css into css folder
  4. Now in your HTML File where you want to include CSS, add {% load static %} On the top of HTML File and Your Path should be like this <link rel="stylesheet" href="{% static 'css/styles.css' %}"> in HTML file.
  5. Then Make Change To Your settings.py in projectfoldername with-

    STATIC_URL = '/static/'

    STATICFILES_DIRS = [ os.path.join(BASE_DIR,'static') ]

    STATIC_ROOT = os.path.join(BASE_DIR, 'assets')

Then Run this command

python manage.py collectstatic

You static file will be copied to New file created by django as assets.

If it does not reflect changes Refer here If it does not work

2 of 2
1

According to the official statement "Generally, the templates folder is created and kept in the sample directory where manage.py lives. This templates folder contains all the templates you will create in different Django Apps."

As a Django projects grow in size it's often more convenient to have all the templates in one place rather than hunting for them within multiple apps.

Just as an additional information for the accepted answer's 1."Statement"

Besides, yes you should have your static folder at App-level and it should work!.

Discussions

python - Not Found: /style.css/ , django - Stack Overflow
I'm trying to create my own website on Django, but some problems stop me and I can't solve them myself. I want to create a sidebar. I found a website with css and HTML code for it. style.css: @... More on stackoverflow.com
🌐 stackoverflow.com
python - Django style.css is not found - Stack Overflow
Error :Not Found: /{ % static 'css/style.css' % } "GET /{ % static 'css/style.css' % } HTTP/1.1" 404 2378 · When I want to link my style.css to Django project it throws an error. More on stackoverflow.com
🌐 stackoverflow.com
CSS is not working (Django Basics)
Max Pinomaa is having issues with: Hi, I'm doing the project on my Mac computer, but the CSS is not working. "Welcome!" is visible. I've checked all the other similar posts. I've ... More on teamtreehouse.com
🌐 teamtreehouse.com
4
July 3, 2017
Why is django not finding my css file?

Is your file style.css or index.css?

I didn't look through your whole github repo but I did find index.css

Edit: found style.css in accounts. I'm on mobile but it may be a name space issue with 2 folders named static. Wish I could help more, just my best guess.

More on reddit.com
🌐 r/djangolearning
6
3
February 19, 2023
🌐
CSEstack
csestack.org › home › add css and static files in django | is your css not loading?
Add CSS and Static Files in Django | Is Your CSS Not Loading?
May 11, 2024 - If the Django project is able to locate the CSS, it will return the path to your CSS file. $ python manage.py findstatic css/style.css Found 'css/style.css' here: <path_to_your_CSS_file> If the CSS static file is not found, it will throw an error as “No matching file found”
Top answer
1 of 3
1

Easy fix, but you will need to dig into Django a bit more.

First, this tag <link rel="stylesheet" href=style.css/> will never work. The tag is written wrong on a few levels. The big problem is that the location is relative, the use of style.css is assumed to be on the same directory level as what ever page/script/etc is being called. The problem is that wsgi.py or similar file is actually the "root" that is "running" the site and has no idea where "style.css" exists and also deos not care.

Styles, image, js, etc are all stored as static assets in Django. This folder is "served" using a static tag that will transform to the correct path per your configuration for local dev and production. Take a look here: https://docs.djangoproject.com/en/3.1/howto/static-files/

I will not explain all the nuance, the Django site does a better job. Instead I will point out how Django is different from static sites or something like PHP. Django is an application running in the CGI (WSGI), there is only one "route" on the server so to speak, all data is served from this one file. PHP can and typically does serve data in a file+directory manner. In PHP/static scenario the location of files is stable compared to Django. In Django the page, url, and the way data is served all come from one point. That means the relationship to static files will be different and not something you can or should control.

Django does not want you to ever serve static files through the CGI (WSGI), that is a waste of CPU and resources and is slow for static. So they have a static system. When running locally with the configuration set up correctly and DEBUG=True then the static keyword will transform to the necessary local path in conjunction with your configuration.

When in production it is assumed that a CDN is used, in that case the static keyword is replaced with the path (URL) to the CDN static files.

The approach Django uses is much more mature than say, Wordpress where use of a CDN can be tricky (I have written custom CDNs for WP many times, not fun).

Walk through the link above, set up your configuration correctly and follow the rules. Django is very interested in your following of the rules, Deviation will only cause pain. I have been primarily a Django dev for almost 10 years now. The problem you ran into got me real good in the beginning, but now CDN and static file management is second nature and definitely more productive than other less mature systems.

2 of 3
0

Set static root on your 'settings.py'.

🌐
Stack Overflow
stackoverflow.com › questions › 68407355 › django-style-css-is-not-found
python - Django style.css is not found - Stack Overflow
Error :Not Found: /{ % static 'css/style.css' % } "GET /{ % static 'css/style.css' % } HTTP/1.1" 404 2378 When I want to link my style.css to Django project it throws an er...
🌐
Devnote
devnote.in › home › blog › django – css file not found | django static files tutorial
Django - CSS File not Found | Django Static Files Tutorial - Devnote
August 21, 2020 - Add a static/your_app/ directory to your_app define a new top-level directory and add that to STATICFILES_DIRS in settings.py.
🌐
PythonAnywhere
help.pythonanywhere.com › pages › DjangoAdminCSSNotWorking
The Django Admin CSS isn't working! | PythonAnywhere Help
May 13, 2015 - There are two ways to fix this. The ugly/hacky way is to add a specific static files mapping pointing at the django admin css folder: url: /static/admin path: /usr/local/lib/python3.10/dist-packages/
Find elsewhere
🌐
Google Groups
groups.google.com › g › django-users › c › aTQ87V1fkPE
Django can't see my static files
The link where your browser fetches the css file (see rendered source head when browsing) to gets 404'ed. If you are using a local server, you could try using a STATIC URL of 127.0.0.1:8000/static/. Note that this will not work if you use runserver on 0.0.0.0, on which case you should use your local IP address.
🌐
Team Treehouse
teamtreehouse.com › community › css-is-not-working-django-basics
CSS is not working (Django Basics) (Example) | Treehouse Community
July 3, 2017 - from django.conf.urls import url, include from django.contrib import admin from django.contrib.staticfiles.urls import staticfiles_urlpatterns from . import views urlpatterns = [ url(r'^courses/', include('courses.urls')), url(r'^admin/', admin.site.urls), url(r'^$', views.hello_world), ] urlpatterns += staticfiles_urlpatterns() ... {% load static from staticfiles %} <!doctype html> <html> <head> <title>{% block title %}{% endblock %}</title> <link rel="stylesheet" href="{% static 'css/layout.css' %}"> </head> <body> <div class="site-container"> {% block content %}{% endblock %} </div> </body> </html>
🌐
Reddit
reddit.com › r/djangolearning › why is django not finding my css file?
Why is django not finding my css file? : r/djangolearning
February 19, 2023 - A group dedicated to learning Django, a Python web framework. ... Sorry, this post was deleted by the person who originally posted it. Share ... Edit: found style.css in accounts. I'm on mobile but it may be a name space issue with 2 folders named static.
🌐
PythonAnywhere
pythonanywhere.com › forums › topic › 29023
Styles.css not found : Forums : PythonAnywhere
January 8, 2021 - I dont know what to do, I have ... | permalink · If you're getting a "no such file or directory" error, then check that your Django configuration refers to directories and files that actually exist....
🌐
Reddit
reddit.com › r/django › can't load static files (css, js, images)
r/django on Reddit: Can't load static files (CSS, JS, images)
January 26, 2023 -

According Django's documentation, I added this to my settings dot py file:

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

Then, my home page looks like this:

{% load static %}

<!DOCTYPE html>

<html class="wide wow-animation" lang="en"> <head> <!-- Site Title--> <title>Home</title> <meta name="format-detection" content="telephone=no"> <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta charset="utf-8"> <link rel="icon" href="{% static 'website/images/favicon.ico' %}" type="image/x-icon">

(Note: I'm just showing the upper side of the page)

But on that page, I just see the text /static/website/images/favicon.ico, the icon is not loading.

I've been dealing with this for hours, could not find any solution, can somebody help me, please?

🌐
Stack Overflow
stackoverflow.com › questions › 50319136 › django-file-style-css-cannot-be-found
python - django file style.css cannot be found - Stack Overflow
May 13, 2018 - from django.contrib import admin from django.urls import path from django.conf.urls import url, include from . import views from django.conf import settings from django.conf.urls.static import static app_name = 'trader' urlpatterns = [ path('', views.index, name='index'), path('admin/', admin.site.urls), url(r'^buy/', include('buy.urls')), ]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) ... root@localhost:/home/robin/www/trader# python3 manage.py findstatic templates/trader/style.css No matching file found for 'templates/trader/style.css'. root@localhost:/home/robin/www/trader# ls -l templates/trader/style.css -rw-r----- 1 www-data www-data 155 May 13 12:46 templates/trader/style.css
🌐
Python Forum
python-forum.io › thread-28019.html
css not working in Django
I am using django 2.2.7 I have a template called index.html (attached). Inside here, I have li tags for which I want to remove the bullet points. So in my style.css file (also attached), I write nav li {list-style-type: none;}. However, when I load...
Top answer
1 of 12
59

For Django to serve static files, you have to make sure you have a couple of settings.

STATIC_URL

This setting specifies what URL should static files map to under. You have that done already.

STATICFILES_DIRS

This specifies all the folders on your system where Django should look for static files. The idea is that you might have a couple of apps within your project, and each app might require a different set of static files. So for organizational purposes, each app might contain a static directory where it will store only its static files. So then Django has to have a way to know where those directories are. This is what this setting is for.

STATIC_ROOT

This setting specifies where Django will copy all the static files to and not where the static files are already at. The idea is that once you leave development into production, Django can't serve static files anymore due to issues I will not go here (it's in the article). However, for production, all static files should be in a single directory, instead of in many like specified in STATICFILES_DIRS. So this setting specifies a directory to which Django will copy all the static files from all files within STATICFILES_DIRS by running the following command:

$ python manage.py collectstatic

Please note this is only necessary once you go into production and also that the directory specified here cannot be the same as any directory specified in STATICFILES_DIRS.

Urls.py

In development for Django to serve your static files, you have to include the static URLs in your urls.py:

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = ...

urlpatterns += staticfiles_urlpatterns()

Once you will complete all of the above things, your static files should be served as long as you have DEBUG = True. Out of the list above, you seem to only complete STATIC_URL. Also please note that all the steps I described above are in the docs you linked in your question (link). It might be a bit confusing in the beginning but if you read it a couple of times, it becomes clearer.

2 of 12
14

Try clearing your cache. If you are using Google chrome go to your settings>clear browsing data> select clear cached images and files then click clear data

🌐
Django Forum
forum.djangoproject.com › using django › mystery errors
Struggling to get a CSS file working - Mystery Errors
June 17, 2023 - Hello, I am trying to get a CSS file to turn the background of the website blue (more of a learning exercise than something practical) I started by using inline CSS and that was fine. I thought the process would be as simple as replacing this inline CSS with a link to a CSS file that had the same code as the previous inline CSS however when doing that I get a 404 error for the css file and the background does not turn blue.