Difficulty with Django and jQuery (why is $ undefined in the admin app?)
Adding this to the top of my .js file fixes it:
var $ = django.jQuery;
I'm not sure how to remove the jquery.init.js file, given that my project doesn't contain any scripts that use $
for something other than jQuery.
Use the Firebug or Web Inspector JS console and type $
and/or jQuery
. That's the simplest way to find out if the library has been loaded correctly. In the unlikely case, that only jQuery is defined, you can wrap your script into it's own scope:
(function($){
// your code here…
})(jQuery);
If nothing is defined at the console, the problem is most likely with the file and I'd try AndiDog's approach to see if there's anything loaded at all.
i solved this problem on this way, you have to include jquery.init.js (often its jquery.init.js from admin) in this file add following lines:
var django = {
"jQuery": jQuery.noConflict(true)
};
var jQuery = django.jQuery;
var $=jQuery;
and u have in whole workspace jquery and $. For better code looking i prefer create my own jquery init file in project.