0

我正在尝试通过 django_select2 库使 select2 在我的 django 应用程序中工作。

我已经完成了库的安装、URL 中的设置以及 forms.py 中所需的更改。

我还添加了 {{ form.media.css }} 和 {{ form.media.js }}。

当我尝试访问它应该工作的页面时,控制台中出现错误

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”.

我尝试在我的 settings.py 文件中添加这些,但我仍然收到错误消息。

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

还有一个答案建议在 django_select2.js 的第一行之后放置一个空格,但我仍然遇到同样的错误。

有什么想法吗?

4

0 回答 0