0

I'm trying to make the select2 work in my django app via django_select2 library.

I've done the installation of the library, setup in URL and the change required in the forms.py.

I have also added {{ form.media.css }} and {{ form.media.js }}.

When I try to access the page where its supposed to work, I get an error in the console

1. The script from “http://127.0.0.1:8000/static/django_select2/django_select2.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.
2. Loading failed for the <script> with source “http://127.0.0.1:8000/static/django_select2/django_select2.js”.

I have tried adding these in my settings.py file but I still get the error.

import mimetypes
mimetypes.add_type("text/css", ".css", True)

Also there was an answer suggesting to put a space after the first line of django_select2.js, but I still got the same error.

Any ideas guys?

chip
  • 3,039
  • 5
  • 35
  • 59
  • How are you serving the file? Is this using the dev server? – Iain Shelvington Dec 28 '19 at 15:59
  • yup, currently in my local computer. once I get it working then I would transfer the codes to my pythonanywhere server – chip Dec 28 '19 at 23:08
  • From the docs - To guess the served files’ content types, this view relies on the mimetypes module from the Python standard library, which itself relies on the underlying platform’s map files. If you find that this view doesn’t return proper content types for certain files, it is most likely that the platform’s map files need to be updated. This can be achieved, for example, by installing or updating the mailcap package on a Red Hat distribution, or mime-support on a Debian distribution. – Iain Shelvington Dec 28 '19 at 23:10

0 Answers0