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?

0

There are 0 best solutions below