In django: Problems with loading jquery with multiple plugins - or: How to load jQuery only once?

330
April 21, 2017, at 00:10 AM

I use django (1.8.16) with a ton of plugins ("apps"). Some are:

  • django-ckeditor==4.5.1
  • django-image-cropping==1.0.3
  • django.contrib.admin
  • django-jquery==3.1.0

I want to use django autocomplete-light (dal for short) (3.2.1, current version) in the admin interface. Now I have the following jquery struggle. dal uses jquery but does not load it itself. It leaves it up to the developer. dal comes with a script "select2.js" registering a function under $.select2.

Now the problem. When a plugin like ckeditor or image-cropping loads jquery the function $.select2 is not reachable any more.

I have created a bug report over at dal but one dev says it is my responsability to load jquery first.

So, how do I load jquery, load it before dal needs it and load it only once?

Answer 1

Per the django-ckeditor docs:

If you have jQuery loaded from a different source just don't set [CKEDITOR_JQUERY_URL] and django-ckeditor will not try to load its own jQuery.

You should make sure you're setting all apps that could load jQuery to not load it, similar to above. Then, use django-jquery to load jquery, making sure that jQuery is available in the console (i.e., try typing console.log($) to see if it's available). Make sure that you put your jQuery template tag above any other template tags loaded by the other libraries.

This should solve any conflicts you're experiencing.

READ ALSO
How do you make a block comment in python? [on hold]

How do you make a block comment in python? [on hold]

I have tried using triple quotes but it only turns the code greenAs if i were to print it

309
Maintaining sessions in Flask (python 2.7) without username or authentication

Maintaining sessions in Flask (python 2.7) without username or authentication

I am new to flaskI am working on building a chatbot

325
Eclipse PyDev Code completion of dynamic class attributes?

Eclipse PyDev Code completion of dynamic class attributes?

I would like to get the code completion in Eclipse with PyDev for the attributes of a class which is dynamically generated

280
Creating a Ubiquity Discovery Sweep Script

Creating a Ubiquity Discovery Sweep Script

I am a network engineer and tasked to run scripts on Ubiquity devices and feel there has to be a way to automate this process

356