Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS not loading wrong MIME type Django

I have installed virtualenv in my localhost to run a django app with 1.8 version but when running it the css and js files doesn't load.

I get

Resource interpreted as Stylesheet but transferred with MIME type application/x-css

I have tried some options but they don't solve the issue either. I am running the same configuration on other PC and it works.

My HTML loads the css with :

<link href="/static/css/bootstrap.css" rel="stylesheet" type="text/css">
like image 647
jesicadev18 Avatar asked Feb 22 '16 15:02

jesicadev18


People also ask

How to solve the MIME type error when loading CSS?

"whitenoise" will solve "MIME type" error then CSS is loaded successfully: Then, set it to "MIDDLEWARE" in "settings.py". Finally, CSS is loaded successfully: MIDDLEWARE = [ # ... "django.middleware.security.SecurityMiddleware", "whitenoise.middleware.WhiteNoiseMiddleware", # Here # ... ] Access the CSS file directly.

Why is my Django CSS not loading?

If your project is unable to locate the CSS or any other status files inside your project directory, it will throw HTTP 404 status code as an error. Is your Django CSS not loading? There are multiple ways of debugging it.

How do I find a static CSS file in Django?

Run manage.py with find static option. If Django project able tp locate the CSS, it will return path to your CSS file. If the CSS static file not found, it will throw an err as “No matching file found” $python manage.py findstatic css/style.css No matching file found for 'css/style.css'.

How to use mimetypes with Django Whitenoise?

If you happen to be using the Django whitenoise plugin, then the mimetypes module is not used, and you need to pass in a dictionary of custom types in settings.py: "whitenoise" will solve "MIME type" error then CSS is loaded successfully: Then, set it to "MIDDLEWARE" in "settings.py". Finally, CSS is loaded successfully:


1 Answers

This particular behaviour varies between the development(DEBUG=True) and deployment environment(DEBUG=False).

So if you are developing locally with DEBUG=False there is a high chance of this error. But once deployed on any server it will work without any error. If you want to avoid this error during development set DEBUG=True

like image 136
M A Rahul Avatar answered Sep 28 '22 14:09

M A Rahul