Refused to apply style from <URL>static/styles.css

Refused to apply style from static/styles.css because its MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Ive been on the error for 2 days now with no luck.

[settings.py]

BASE_DIR = Path(__file__).resolve().parent.parent 

STATIC_URL = '/static/' 
STATIC_ROOT = BASE_DIR / 'staticfiles' 
STATICFILES_DIRS = [ BASE_DIR / 'myapp' / 'static', ]

base.html

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

I also am running
python manage.py collectstatic --noinput

So when I am in production its picking up nothing in my static folder I’m so confused help please!

Welcome @nickmharrison !

Side Note: When posting code here, enclose the code between lines of three
backtick - ` characters. This means you’ll have a line of ```, then your code,
then another line of ```. This forces the forum software to keep your code
properly formatted. (I have taken the liberty of correcting your original posts.
Please remember to do this in the future.)

Also, please don’t try to put the full description of the issue in the title. The title should be a short description of the issue. The full details should be posted in the body of the post.

We need more details about your environment.

Please post:

  • How are you running your project?
  • What web server are you using (Apache? Nginx?) and how is it configured for your project?

We’re probably going to need to ask more questions, but this will get us started.

1 Like

1.Gunicorn
2.Whitenoise

repo : GitHub - nickmharrison/nickmharrison: Website

What are the commands you’re using to run this?

What do the gunicorn (and possibly system) logs show for the requests for your static files?

You’ve got two entries in your settings file for MIDDLEWARE - this means that your first definition containing the reference to whitenoise is not being used.

  1. gunicorn demo.wsgi:application
  2. 404
  3. Fixed

No, it’s not. You’ve still got two definitions for MIDDLEWARE with Whitenoise defined in the first one.

Code didn’t push, pushing right now.

fixed! Added middleware together and I put staticfiles in my myapp directory instead of root. Thank you Ken u are a goat <3 :goat: