# CSS files won't load

**URL:** <https://forum.djangoproject.com/t/css-files-wont-load/17540>\
**Category:** Mystery Errors\
**Created:** [December 10, 2022, 5:58am UTC](https://forum.djangoproject.com/t/css-files-wont-load/17540 "2022-12-10T05:58:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariostg](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mariostg/32/10901_2.png) [@mariostg](https://forum.djangoproject.com/u/mariostg)\
**Post date:** [December 10, 2022, 5:58am UTC](https://forum.djangoproject.com/t/css-files-wont-load/17540/1 "2022-12-10T05:58:58Z")

</div>

I have no idea what I can be missing.  
Relevant portion of setting.py, running MacOS Ventura|Montgomery,python3.10, django4.1.3

```auto
DEBUG = True

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'geographie',
    'habitat',
    'siteornitho',

    'debug_toolbar'
]

STATIC_URL = '/static/' #with or without slash at beginning	
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# STATICFILES_DIRS=[
# "siteornitho/static"
# ]

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

```

base.html

```auto
<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link type="text/css" href= "{% static 'siteornitho/css/main.css' %} ">
    <link rel="stylesheet" href= "{% static 'siteornitho/css/fiche.css' %} ">
    <title>Document</title>
</head>

```

Static Structure populated by mange.py collectstatic

```auto
static
├── admin
│ ├── css
│ │ ├── autocomplete.css
│ │ ├── base.css
│ │ ├── changelists.css
│ │ ├── dark_mode.css
│ │ ├── dashboard.css
│ │ ├── fonts.css
│ │ ├── forms.css
│ │ ├── login.css
│ │ ├── nav_sidebar.css
│ │ ├── responsive.css
│ │ ├── responsive_rtl.css
│ │ ├── rtl.css
│ │ ├── vendor
│ │ └── widgets.css
├── debug_toolbar
│ ├── css
│ │ ├── print.css
│ │ └── toolbar.css
└── siteornitho
    ├── css
    │ ├── fiche.css
    │ └── main.css

```

[http://127.0.0.1:8000/static/admin/css/base.css](http://127.0.0.1:8000/static/admin/css/base.css) WORKS  
[http://127.0.0.1:8000/static/siteornitho/css/main.css](http://127.0.0.1:8000/static/siteornitho/css/main.css) NOT FOUND  
[http://127.0.0.1:8000/static/siteornitho/css/fiche.css](http://127.0.0.1:8000/static/siteornitho/css/fiche.css) NOT FOUND

[http://127.0.0.1:8000/media/siteornitho/images/2022-10-24-16-03-40.JPG](http://127.0.0.1:8000/media/siteornitho/images/2022-10-24-16-03-40.JPG) WORKS

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 10, 2022, 1:12pm UTC](https://forum.djangoproject.com/t/css-files-wont-load/17540/2 "2022-12-10T13:12:25Z")

</div>

How are you running this? (Are you testing using runserver, or some other server?)

What is your `DEBUG` setting?

You show your `STATICFILES_DIRS` setting as being commented out, why?

---

<div class="post-metadata">

**Author:** ![mariostg](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mariostg/32/10901_2.png) [@mariostg](https://forum.djangoproject.com/u/mariostg)\
**Post date:** [December 10, 2022, 1:37pm UTC](https://forum.djangoproject.com/t/css-files-wont-load/17540/3 "2022-12-10T13:37:14Z")

</div>

@KenWhitesell. Using runserver. As indicated above, DEBUG=True.

I commented out STATICFILES\_DIRS after I ran collectstatic to see what difference it would make.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 10, 2022, 2:45pm UTC](https://forum.djangoproject.com/t/css-files-wont-load/17540/4 "2022-12-10T14:45:58Z")

</div>

The runserver does not automatically serve static files from where collectstatic copies files. It serves files from the directories that STATICFILES\_DIRS specifies. If you want to serve files from your STATIC\_ROOT directory, then you need to add STATIC\_ROOT to STATICFILES\_DIRS.

See [The staticfiles app | Django documentation | Django](https://docs.djangoproject.com/en/4.1/ref/contrib/staticfiles/) and [Settings | Django documentation | Django](https://docs.djangoproject.com/en/4.1/ref/settings/#staticfiles-dirs) for more detailed information.

---

<div class="post-metadata">

**Author:** ![mariostg](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mariostg/32/10901_2.png) [@mariostg](https://forum.djangoproject.com/u/mariostg)\
**Post date:** [December 11, 2022, 1:27am UTC](https://forum.djangoproject.com/t/css-files-wont-load/17540/5 "2022-12-11T01:27:49Z")

</div>

Well, what I uderstand of STATICFILES\_DIR as I read again this section [How to manage static files (e.g. images, JavaScript, CSS) | Django documentation | Django](https://docs.djangoproject.com/en/4.1/howto/static-files/#configuring-static-files) is that if I don’t have static files outside my apps I don’t have to specify anything in it. Hence I set STATICFILES\_DIR=

According to above link:

1. I have django.contrib.staticfiles in INSTALLED\_APPS
2. I have STATIC\_URL = ‘static/’
3. 
  - am using the static template tag in my base.html file

4. I reorganized the folder structure inside the siteornitho app like the tree below as suggested in bullet 4 of Configuring Static Files section

```auto
siteornitho app
├── static
│ └── siteornitho
│ └── css
│ ├── fiche.css
│ └── main.css

```

In light of all this. as far as it goes for serving my files by runserver it should be ok since DEBUG is true and django.contrib.staticfiles is in INSTALLED\_APPS

Regarding your comment about adding STATIC\_ROOT inside STATICFILES\_DIR, when I do this:

```auto
STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS=[STATIC_ROOT]

```

it throws an error:

django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

**ERRORS:**  
**?: (staticfiles.E002) The STATICFILES\_DIRS setting should not contain the STATIC\_ROOT setting.**

WARNINGS:  
?: (staticfiles.W004) The directory ‘/Users/mariost-gelais/Documents/programming/python/guidedessites/static’ in the STATICFILES\_DIRS setting does not exist.

Anyway, serving files from STATIC\_ROOT directory is not necessary until I can at least serve some css

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 11, 2022, 2:37am UTC](https://forum.djangoproject.com/t/css-files-wont-load/17540/6 "2022-12-11T02:37:51Z")

</div>

Ok, let’s take a step back.

First a side note: Serving static files in development is completely different than serving static files in production. As a general rule, STATIC\_ROOT should be completely outside your project. In a production environment, Django will not be serving those files and shouldn’t have access to them. As a result, while I’m surprised by that error message, it does make sense.

In development, it’s the staticfiles app that serves static files. This means that the only settings that matter are [STATIC\_URL](https://docs.djangoproject.com/en/4.1/ref/settings/#static-url), [STATICFILES\_FINDERS](https://docs.djangoproject.com/en/4.1/ref/settings/#staticfiles-finders), and [STATICFILES\_DIRS](https://docs.djangoproject.com/en/4.1/ref/settings/#staticfiles-dirs) (if the finder is configured).

The STATIC\_URL is the prefix used for static files. You have STATIC\_URL = ‘static/’, which means that any url requested as `static/whatever/file.xxx` is going to look for the file named `file.xxx` in a directory named `whatever` in _any_ of the directories defined in STATICFILES\_DIRS (if `FileSystemFinder` is defined in the finders) and in the `static` directory of each app (if `AppDirectoriesFinder` is defined).

So, based on what I’m understanding from what I’m seeing so far, you have an app named `siteornitho`, with a file in that app in a directory structure `static/siteornitho/css/main.css`. If you have STATICFILES\_FINDERS configured with the `AppDirectoriesFinder` (which I don’t see) along with the `staticfiles` app (which I do see), along with the static reference to `siteornitho/css/main.css` (which I also see), then this _should_ work. (It works for me using these names in my test system.)

Note, you can test access to static files using the [`findstatic`](https://docs.djangoproject.com/en/4.1/ref/contrib/staticfiles/#findstatic) command.

---

<div class="post-metadata">

**Author:** ![mariostg](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mariostg/32/10901_2.png) [@mariostg](https://forum.djangoproject.com/u/mariostg)\
**Post date:** [December 12, 2022, 3:50am UTC](https://forum.djangoproject.com/t/css-files-wont-load/17540/7 "2022-12-12T03:50:30Z")

</div>

I took several steps back after reading your feedback. Back to square one, I returned to the django tutorial and git cloned it. The settings in this project are very basic for handling of static files:

–STATIC\_URL = ‘/static/’ and  
–‘django.contrib.staticfiles’ in INSTALLED\_APPS  
–project has a folder /polls/static/polls that holds style.css.  
This is all working fine.

So I mimicked this on one of the app in my project. Still not working. Then I realized I had DEBUG=False. I don’t recall having switched this to false. So bizarre but pretty much a week-end wasted. On the positive, it forced me to read and read again the docs.

Thanks for your time Ken.
