jquery - django 管理和自动完成灯 : Select2: An instance of jQuery or a jQuery-compatible library was not found

标签 jquery python django django-admin django-autocomplete-light

对于我尝试在管理中对其进行编码的字段,自动完成灯小部件未完全加载。相反,我得到以下信息

Select2: An instance of jQuery or a jQuery-compatible library was not found. Make sure that you are including jQuery before Select2 on your web page.



旁边有一个只有一个选项的选择框。

这类似于之前关于 select2 库的几个问题,大多数解决方案都涉及重新排序 settings.py 中的文件或运行 python manage.py collectstatic。但到目前为止,这些都没有对我有用。

任务是在我的网页上的 Select2 之前包含 jQuery...怎么做?

最佳答案

我遇到了同样的问题,我能够通过重新配置 INSTALLED_APPS 来解决它在我的 settings.py文件以确保'dal''dal_select2'都包含在 'django.contrib.admin' 之前。
这个小花絮包含在 installation documentation 中为 django-autocomplete-light ,虽然我在最初的通读中错过了它:

Then, to let Django find the static files we need by adding to INSTALLED_APPS, before django.contrib.admin and grappelli if present:

'dal',
'dal_select2',
# 'grappelli',
'django.contrib.admin',

This is to override the jquery.init.js script provided by the admin, which sets > up jQuery with noConflict, making jQuery available in django.jQuery only and not $.


附言我最终发现 django 2.x+ 现在有一个 built-in for auto-complete fields .我最终改为使用它,并强烈推荐它以降低开销/开发成本。

关于jquery - django 管理和自动完成灯 : Select2: An instance of jQuery or a jQuery-compatible library was not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45665527/

相关文章:

python - 从两个多维 numpy 数组复制到另一个不同形状的数组

Azure 应用服务上的 Python 代码运行速度比本地慢 10 倍

python - django 中的可编辑数据表,由 mongodb 支持

javascript - 为什么 replaceAll 方法添加的元素比我实际拥有的要多?

python - 就地反转字典

python - python中静态变量和实例变量的区别。它们甚至存在吗?

Django:如何将自定义字段序列化为 fixture 并将其加载回来

jquery - 使用jquery跨域webmethod调用

javascript - Skype Web SDK 登录无法正常工作

jquery - TypeScript 回调没有在其签名中完全实例化类