[Django]-ModelForm and ModelSelect2Widget (django-select2)

4👍

Found the solution:

{{ form.media.js }}

needs to be after the import of jquery.

5👍

Did you follow all the steps in the getting started section?

  1. Add django_select2 to your INSTALLED_APPS in your project settings.

  2. Add django_select to your urlconf if you use any ModelWidgets:

    url(r'^select2/', include('django_select2.urls')),
    
  3. Add the CSS to the head of your Django template:

    {{ form.media.css }} 
    
  4. Add the JavaScript to the end of the body of your Django template:

    {{ form.media.js }}
    

Also, there appears to be an external dependency not provided by the module itself:

External Dependencies

jQuery version 2 This is not included in the
package since it is expected that in most scenarios this would already
be available.

👤ritlew

-1👍

Well, it happens to me too recently… And turns out that the jquery script

(<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>)

should be placed first before any scripts that use jquery (it will use jquery, but the jquery hasn’t been called).

Leave a comment