CSS not loading wrong MIME type Django

后端 未结 5 2036
星月不相逢
星月不相逢 2020-12-03 21:59

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         


        
相关标签:
5条回答
  • 2020-12-03 22:31

    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).

    0 讨论(0)
  • 2020-12-03 22:43

    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.)

    0 讨论(0)
  • 2020-12-03 22:43

    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)
    
    0 讨论(0)
  • 2020-12-03 22:45

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

    import mimetypes
    mimetypes.add_type("text/css", ".css", True)
    
    0 讨论(0)
  • 2020-12-03 22:48

    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'
    }
    
    0 讨论(0)
提交回复
热议问题