Are you using a jQuery plugin, for instance
jQuery UI, to spice up the Django admin site?
Then you might get either an error like “foo is not a function”
(Firebug) or “Object … has no method foo”
(Chrome Developer Tools). Confused
foo should be defined in the plugin? Don’t worry, the
solution is simple.
Actually, the reason and solution are in the Django admin site documentation if you know where to look. The reason is this:
Django’s jQuery is namespaced as
This prevents collisions with other scripts or libraries. It also prevents you from blindly using code you find on the internet. ;-)
Possible solutions are:
- Include your own copy of jQuery which does ‘pollute’ the global namespace.
- Make sure your plugin/code uses
django.jQueryinstead of just
- Create a
$) variable yourself.
As the documentation says, the benefit of the first option is that you can use a different (newer) version of jQuery, if your want or need to.
The second option might mean that you’ll have to download the development version of the plugin, change the code, and minify it yourself.
For what it’s worth, I chose the second option and changed the custom jQuery UI code I had downloaded. Your use case might benefit from another solution…