#32041 closed Cleanup/optimization (fixed)
Document Windows caveats in mimetypes warning.
Reported by: | Peter Marheine | Owned by: | Peter Marheine |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When using manage.py runserver
for development on Windows, I've had issues with some static files being served with incorrect MIME types- particularly javascript files were being served with content type text/plain
, for which most browsers will emit a warning and if the file is being loaded as a javascript module they will refuse to execute it (which is troublesome for development as you might expect).
In Django this happens in django.views.static.serve
, which delegates to Python's mimetypes
module to guess the MIME type of a file by name. On Windows mimetypes
gets configuration from the registry, such as the key HKEY_CLASSES_ROOT\.js\Content Type
(if it exists) for .js files.
Where this becomes problematic and I think it may be appropriate for Django to do something about it is that it's very easy for users to have incorrect MIME type settings in the Windows registry. I found that it was set to text/plain
on this machine, which appears to have been set by either Visual Studio or VS Code and this sort of problem also seems to affect Go in the same way (https://github.com/golang/go/issues/32350) as well as being somewhat common among Django users (https://stackoverflow.com/q/16303098/2658436).
I also found (by inspecting the registry in a clean Windows sandbox) that Windows doesn't seem to ship with a MIME for .js specifically, so arguably this is just a problem with Windows in that it's easy to misconfigure. It's unclear to me what a good solution to this might look like, since if a user wanted to configure a weird MIME type for some file then the registry would be the place to do it, but Django can't tell the difference between a weird configuration that a user specifically configured and one that ended up that way accidentally. It may be most appropriate to document this particular pitfall and not make any code changes.
#6484 is a very old ticket that's related- this might be considered a point showing there is demand for packaging MIME type definitions to use on Windows.
Change History (7)
comment:1 by , 4 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 4 years ago
Resolution: | invalid |
---|---|
Status: | closed → new |
Version: | 3.1 → master |
From some discussion on django-developers, I'm reopening this; though a code change doesn't seem warranted, the staticfiles documentation can be updated to mention the Windows pitfalls as it already does for some Linux distributions.
comment:3 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 4 years ago
Component: | Core (Management commands) → Documentation |
---|---|
Summary: | Detected MIME types can easily be wrong on Windows → Document Windows caveats in mimetypes warning. |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
Django relies on
mimetypes
library, so that's not an issue (if any) in Django but in Python. We shouldn't add any workarounds in Django. Please report it in https://bugs.python.org. You can find several related reports in Python's bugs tracker, e.g. issue10551, so probably it's already reported.