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">
"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.
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.
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'.
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With