在 django_select2 中,field_id 参数未在 ajax url 中传递

Posted

技术标签:

【中文标题】在 django_select2 中,field_id 参数未在 ajax url 中传递【英文标题】:In django_select2, the field_id parameter is getting not passed in ajax url 【发布时间】:2019-02-22 08:04:05 【问题描述】:

当我使用django_select2 时,field_id 参数没有被传递以获取 URL select2/fields/auto.json

因此,它会引发 404 错误。

有没有我遗漏的配置?

python3.6, django2.1django_select2 LIB_VERSION = v4.0.5 django_select2-6.3.1.dist-info

所有都是最新版本。

我不确定问题出在哪里,但我可以看到在没有 field_id 的情况下调用了 GET URL select2/fields/auto.json。当我使用 field_id 手动执行它并生成密钥时,我得到了正确的结果。

【问题讨论】:

【参考方案1】:

这里是django-select2 的维护者。 Saldy 我们不再维护版本 4。这是一个非常旧的版本,在版本 5 中我们进行了完全重写。这解决了很多问题。也许这个也是。我强烈建议更新到最新版本。特别是如果您使用的是 Django 2.1 和 Python 3.6。

【讨论】:

它只是最新版本。 4.0.5 是 conf.py 中的 LIB 版本。【参考方案2】:

您可能缺少获取字段 ID 并将其添加到请求中的 JS - 确保您在视图中有 form.media.js ,或者使用 $('.django-select2').djangoSelect2(); 手动初始化字段

在此处查看文档:https://django-select2.readthedocs.io/en/latest/django_select2.html#javascript

【讨论】:

以上是关于在 django_select2 中,field_id 参数未在 ajax url 中传递的主要内容,如果未能解决你的问题,请参考以下文章