Django admin - jQuery namespace

后端 未结 3 417
故里飘歌
故里飘歌 2021-01-18 01:14

I\'m trying to use certain jQuery plugins in my Django admin site.

Django admin sets the jQuery namespace to django.jQuery (to avoid conflicts)

相关标签:
3条回答
  • 2021-01-18 01:55

    Actually, most plugins will require "jQuery" - not $ - to be available, and then provide $ themselves as in dmidz's answer.

    Therefore, insert

    var jQuery = django.jQuery;
    

    before your external references. If you're loading a bunch of thirdparty jQuery plugins, put the above line in a script tag that preceeds the plugins.

    See also my question five months ago How to provide $ to third-party, external jQuery plugins in Django admin

    0 讨论(0)
  • 2021-01-18 02:01

    I suggest you to leave the jQuery in django.jQuery namespace wich is a good idea when using cms with different modules that could conflict. But you wrap your plugin within such :

    ;(function($){
      // here $ is only in this scope and so totally inobrusive
      // plugin code
    })(django.jQuery);
    
    0 讨论(0)
  • 2021-01-18 02:13

    Someone else had a similar problem and used the deconflict function: http://www.lokkju.com/blog/archives/143

    I'm not sure what version Django uses, but I think the point of using the django namespace is that it can use its own version of jQuery for its internal operations, but still let you use a different version for your own work.

    0 讨论(0)
提交回复
热议问题