Iustinian Olaru
Iustinian Olaru

Reputation: 1337

Why is my django application not serving .css files?

I have an issue with serving a specific css file in my django app and I can't seem to find the solution to it, hopefully someone can help.

I have a website PersonalWebsite and in there I have three apps, the important one being the dashboard. I decided to separate the static files of each app and then also the static files of the base website so my folder structure is like this:

PersonalWebsite
|
|static
    |PersonalWebsite
           |
           |css
             | style.css
           |fonts
             | font.ttf
|dashboard
    |
    |static
       |dashboard
           |css
           | style.css

When I open up the website I can see all files from the static/PersonalWebsite are being served, however the ones from static/dashboard are not. Could anyone provide some insight as to what is wrong? I have run the collectstatic command several times and that one detects the file and I see it being copied into the root folder.

These are my static settings. I added boot because in that one I have bootstrap downloaded.

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

Upvotes: 0

Views: 208

Answers (3)

Iustinian Olaru
Iustinian Olaru

Reputation: 1337

I managed to figure out the issue. While I set everything up for the base.html css code, I forgot to link the dashboard/style.css file into the base.html head tag. So the file was being loaded and everything but the file was not used by the html because of the missing link.

Upvotes: 1

Mayank Rathi
Mayank Rathi

Reputation: 1

If i understood your question correctly, then use this command it may help you as it did work for me:

python manage.py collectstatic

Upvotes: 0

Aakash Kothari
Aakash Kothari

Reputation: 205

If I understand your question correctly, you aren't able to load your static files onto your website. You may not have loaded the static files onto your templates. Make sure you load them with the correct path Ex:

{% load 'dashboard/static/dashboard/style.css' %}

Upvotes: 0

Related Questions