Django 管理员 - jQuery 命名空间 [英] Django admin - jQuery namespace
问题描述
我正在尝试在我的 Django 管理站点中使用某些 jQuery 插件.
I'm trying to use certain jQuery plugins in my Django admin site.
Django admin 将 jQuery 命名空间设置为 django.jQuery
(以避免冲突)
Django admin sets the jQuery namespace to django.jQuery
(to avoid conflicts)
如果我没有 jQuery 的默认 $
命名空间,插件将无法工作,对吗?
If I don't have the default $
namespace for jQuery, the plugins won't work, will they ?
我必须做类似的事情
window.$ = django.jQuery
?
如何&我在哪里可以更改整个管理站点的这个命名空间?
How & where can I change this namespace for the whole admin site ?
推荐答案
实际上,大多数插件都需要jQuery" - 而不是 $ - 才能使用,然后像 dmidz 的回答一样自行提供 $.
Actually, most plugins will require "jQuery" - not $ - to be available, and then provide $ themselves as in dmidz's answer.
因此,插入
var jQuery = django.jQuery;
在您的外部参考之前.如果您正在加载一堆第三方 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.
另请参阅我五个月前的问题 如何在 Django admin 中向第三方、外部 jQuery 插件提供 $
See also my question five months ago How to provide $ to third-party, external jQuery plugins in Django admin
这篇关于Django 管理员 - jQuery 命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!