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
Resour
If you're using Centos and having similar issues (mine were with svgs) then you might need to install the mailcap
package if it doesn't exist (as per this answer).
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)
Adding following snippet into settings.py
file may fix your problem:
import mimetypes
mimetypes.add_type("text/css", ".css", True)
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_MIMETYPES = {
'.xsl': 'application/xml'
}