CSS Not Loading Wrong Mime Type Django

CSS not loading wrong MIME type Django

Adding following snippet into settings.py file may fix your problem:

import mimetypes
mimetypes.add_type("text/css", ".css", True)

Getting Mime Type Error when loading Django CSS

It's supposed to be text/css mimetype, like: <link rel="stylesheet" type="text/css" href="mystyle.css">

Django: Refused to apply style from ... because its MIME type ('text/html') is not a supported stylesheet MIME type

all i did was add this line in my base.html head section

<head>
...
<base href="{% static '/' %}">
</head>

Django CSS/JS MIME type (“text/html”) mismatch Error

check your static files settings in settings.py:

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

and add this in master urls.py:

from django.conf.urls.static import static

if settings.DEBUG:
urlpatterns = urlpatterns + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

CSS not working in Django admin: The resource from [css file url] was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff

I got the error

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

because one of my Cloudflare manually created firewall rules blocked CSS URLs.
I discovered this when opened my Cloudflare dashboard and sow that firewall rule was applying 'JS challenge' to the URLs like https://[my-website]/static/admin/css/.

So if your website can not load some resources and you get the error about MIME type please check your Cloudflare dashboard or try to temporary disable it.



Related Topics



Leave a reply



Submit