My browser (firefox) console confirms receiving files with status 200 but firefox gives me this:
The stylesheet http://localhost:8000/css/full-width-pics.css was not loaded because its MIME type, "text/html", is not "text/css". localhost:8000
The stylesheet http://localhost:8000/css/mainstyle.css was not loaded because its MIME type, "text/html", is not "text/css". localhost:8000
Just as further poof that Django is serving the files but just with the wrong mimetype: All files give status code 200:
[05/Jul/2015 08:52:33]"GET / HTTP/1.1" 200 6263
[05/Jul/2015 08:52:33]"GET /css/full-width-pics.css HTTP/1.1" 200 6263
[05/Jul/2015 08:52:33]"GET /js/bootstrap.min.js HTTP/1.1" 200 6263
[05/Jul/2015 08:52:33]"GET /css/mainstyle.css HTTP/1.1" 200 6263
[05/Jul/2015 08:52:33]"GET /js/jquery.js HTTP/1.1" 200 6263
This is what I've found out so far.
Django uses python to guess mime types. Python uses the system it runs on to guess mime types. In windows that's somewhere in the registry. I'm on Ubuntu so for me that is in /etc/mime.types.
I found this line in /etc/mime.types:
text/css css
That means the problem is not with my system. Is the problem with python then? No. Running the following:
import mimetypes
mimetypes.guess_type("test.css")
gives me the following:
('test/css', none)
I've tried some 'hacks' from other stackoverflow answers. One hack was to add mimetypes.add_type("text/css", ".css", True)
to settings.py. It didn't work.
Another was to add url(r'.*\.css$', views.css),
to urls.py and this to views.py:
def css(request):
filename = request.path.strip("/")
data = open(filename, "rb").read()
return HttpResponse(data, mimetype="text/css")
Also didn't work. I removed both of them. Now I just want to know why this is happening and how I can properly fix it. I'm sure the problem is with Django but I'm not sure where.
One more important piece of information. This only started happening after I started using template inheritance. Before <link href="css/full-width-pics.css" rel="stylesheet" type="text/css" />
was directly in index.html and it worked fine. Now it is in base.html and index.html 'extends' base.html. I'm learning Django so I just started using template inheritance.
Thanks if you've even read all this.