Skip to content

Commit 4ab012d

Browse files
authored
Updated Troubleshooting documentation: simpler mimetype workaround for .js file (#2047)
simpler work-around for incorrect MIME type for toolbar.js, and example of console error message.
1 parent cda70d3 commit 4ab012d

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

docs/changes.rst

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Pending
99
* Converted to Django Commons PyPI release process.
1010
* Fixed a crash which occurred when using non-``str`` static file values.
1111
* Documented experimental async support.
12+
* Improved troubleshooting doc for incorrect mime types for .js static files
1213

1314
5.0.0-alpha (2024-09-01)
1415
------------------------

docs/installation.rst

+35-9
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,41 @@ option.
195195
Troubleshooting
196196
---------------
197197

198-
On some platforms, the Django ``runserver`` command may use incorrect content
199-
types for static assets. To guess content types, Django relies on the
200-
:mod:`mimetypes` module from the Python standard library, which itself relies
201-
on the underlying platform's map files. If you find improper content types for
202-
certain files, it is most likely that the platform's map files are incorrect or
203-
need to be updated. This can be achieved, for example, by installing or
204-
updating the ``mailcap`` package on a Red Hat distribution, ``mime-support`` on
205-
a Debian distribution, or by editing the keys under ``HKEY_CLASSES_ROOT`` in
206-
the Windows registry.
198+
If the toolbar doesn't appear, check your browser's development console for
199+
errors. These errors can often point to one of the issues discussed in the
200+
section below. Note that the toolbar only shows up for pages with an HTML body
201+
tag, which is absent in the templates of the Django Polls tutorial.
202+
203+
Incorrect MIME type for toolbar.js
204+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
205+
206+
When this error occurs, the development console shows an error similar to:
207+
208+
.. code-block:: text
209+
210+
Loading module from “http://127.0.0.1:8000/static/debug_toolbar/js/toolbar.js” was blocked because of a disallowed MIME type (“text/plain”).
211+
212+
On some platforms (commonly on Windows O.S.), the Django ``runserver``
213+
command may use incorrect content types for static assets. To guess content
214+
types, Django relies on the :mod:`mimetypes` module from the Python standard
215+
library, which itself relies on the underlying platform's map files.
216+
217+
The easiest workaround is to add the following to your ``settings.py`` file.
218+
This forces the MIME type for ``.js`` files:
219+
220+
.. code-block:: python
221+
222+
import mimetypes
223+
mimetypes.add_type("application/javascript", ".js", True)
224+
225+
Alternatively, you can try to fix your O.S. configuration. If you find improper
226+
content types for certain files, it is most likely that the platform's map
227+
files are incorrect or need to be updated. This can be achieved, for example:
228+
229+
- On Red Hat distributions, install or update the ``mailcap`` package.
230+
- On Debian distributions, install or update the ``mime-support`` package.
231+
- On Windows O.S., edit the keys under ``HKEY_CLASSES_ROOT`` in the Windows
232+
registry.
207233

208234
Cross-Origin Request Blocked
209235
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)