In django_select2, the field_id parameter is getting not passed in ajax url

1.5k views Asked by At

While I am using django_select2, the field_id parameter is not getting passed to get URL select2/fields/auto.json.

Due to this, it throws 404 error.

Is there any configuration I am missing?

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

All are latest versions only.

I am not sure where is the problem but I can see that GET URL select2/fields/auto.json is called without field_id. When I manually execute it with field_id with the key generated, I am getting the proper results.

2

There are 2 answers

1
codingjoe On

Here is the maintainer of django-select2. Saldy we no longer maintain version 4. This is a really old version and in version 5 we did a complete rewrite. That solved a lot of issues. Maybe this one too. I highly suggest to update to the latest version. Especially if you are using Django 2.1 and Python 3.6.

0
Andrea Crawford On

You might be missing the JS that grabs the field ID and adds it to the request -- make sure you have {{ form.media.js }} in the view, or initialize the field manually using $('.django-select2').djangoSelect2();

See the docs here: https://django-select2.readthedocs.io/en/latest/django_select2.html#javascript