CSS Not Loading Wrong MIME Type Django
Answer :
Adding following snippet into settings.py
file may fix your problem:
import mimetypes
mimetypes.add_type("text/css", ".css", True)
open your Chrome by F12 Developer Tool and check what you actually received. In my case, the CSS file actually redirected to another page. so MIME is text/html
not text/css
(My English is not very good.)
I ran into this issue during development (production was using Nginx and serving from /static_cdn folder without any issues).
The solution came from the Django docs: https://docs.djangoproject.com/en/3.1/howto/static-files/#serving-static-files-during-development
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Comments
Post a Comment