I have this weird problem. I am trying to include css files from the static directory, the browser downloads the content of the CSS file but it says the server is sending the css with mime-type:text/plain
It's best explained here - http://stackoverflow.com/questions/23452967/jinja2-static-files-mime-type-always-text-plain. I am unable to include any CSS file.
Flask does not do this on a clean install with everything setup properly so without access to the code it will be very hard to actually work out what you are doing wrong.
So here's the code
layout.html - http://pastebin.com/p0tERJtW
hello.py - http://pastebin.com/gQm3XXgz
index.html - http://pastebin.com/DFB7HRNU
This is bugging me like nothing has ever did.
Can you run this and tell me what the output is:
import mimetypes
print(mimetypes.guess_type('style.css'))
('text/plain', None)
This is what I get :(
In chrome can you load http://localhost:5000/static/css/style.css?test (assuming that is the correct URL) and change the 'test' to a random string.
In the network tab of dev tools can you print screen the headers tab for the request.

in /flask/helpers.py you will find the following in send_file():
if filename is not None:
if not os.path.isabs(filename):
filename = os.path.join(current_app.root_path, filename)
if mimetype is None and (filename or attachment_filename):
mimetype = mimetypes.guess_type(filename or attachment_filename)[0]
if mimetype is None:
mimetype = 'application/octet-stream'
can you add a print(mimetype) after it and then post what is printed to the terminal.
I still get "text/plain"
127.0.0.1 - - [05/May/2014 20:52:05] "GET / HTTP/1.1" 200 -
This is the mime-type :: text/plain
127.0.0.1 - - [05/May/2014 20:52:05] "GET /static/css/style.css HTTP/1.1" 200 -
127.0.0.1 - - [05/May/2014 20:52:07] "GET /favicon.ico HTTP/1.1" 500 -
I somehow misread this comment.
The python mimetypes module pulls the values from the registry on windows so somehow your registry has got a bit messed up.
If you open regedit and go to the HKEY_CLASSES_ROOT there should be a key .css/Content Type with value text/css. If there is then I have no idea what is happening, if there isn't then that is the confirmation that your registry is borked - I've got no real suggestions of what to do to fix it (save for manually adding each one you need again). If you have another windows machine then I guess you could export the HKEY_CLASSES_ROOT and then import it into the broken one although make sure you backup the registry first.
My registry is indeed broken. Found text/plain. Changed it and it works fine.. Absolute thanks for that. But I suspect that NuSphere PhpED has done this. The default value for .css shows to be PhpED_css_file.
Sounds like a good time to change editors ;)
I work with ST3. That was a test to see whether NuSphere community went dead or not 'coz they just seem to be increasing the version number with hardly any new feature. That evaluation version screwed two days of my life.
@praveenpuglia Can you close the issue :)
You can also fix this with:
import mimetypes
mimetypes.add_type('text/css', '.css')
This may be preferable because it doesn't rely on system configuration.
I had the same issue with JS files 馃槀 Found out that windows registry had text/plain set. I wonder if it's a safe solution...
My registry is indeed broken. Found
text/plain. Changed it and it works fine.. Absolute thanks for that. But I suspect that NuSphere PhpED has done this. The default value for .css shows to be PhpED_css_file.
And here , it was VisualStudio ;)
i had the similar problem with .js files.
Thanks, you saved my time. What goes wrong with windows registry?
maybe, some installers do it?
anyway, Linux is less buggy :)
Most helpful comment
I somehow misread this comment.
The python mimetypes module pulls the values from the registry on windows so somehow your registry has got a bit messed up.
If you open regedit and go to the
HKEY_CLASSES_ROOTthere should be a key.css/Content Typewith valuetext/css. If there is then I have no idea what is happening, if there isn't then that is the confirmation that your registry is borked - I've got no real suggestions of what to do to fix it (save for manually adding each one you need again). If you have another windows machine then I guess you could export theHKEY_CLASSES_ROOTand then import it into the broken one although make sure you backup the registry first.