我正在处理的项目使用了一个 RGBField,它将这个脚本插入到模板中(它在 django 的深处某处,因为我找不到它所在的位置):
<script type="text/javascript">
(function($){
$(document).ready(function(){
$('#id_color').each(function(i, elm){
// Make sure html5 color element is not replaced
if (elm.type != 'color') $(elm).colorPicker({"colors": ["f1c40f", "2ecc71", "9b59b6", "e74c3c", "34495e", "3498db", "1abc9c", "f39c12", "d35400"]});
});
});
})('django' in window && django.jQuery ? django.jQuery: jQuery);
</script>
在控制台中我收到一个错误:Uncaught ReferenceError: jQuery is not defined
我无法检查错误发生的位置,但删除 RGBField 可以防止该问题。
项目中使用了 Jquery,如果我在模板本身中使用 jQuery,它可以正常工作(因此模板本身不是问题)。
我已将 django-jquery 添加到项目中,并包含{% load staticfiles %}
在模板的开头。不能解决问题。
我一直很高兴地忽略了整个事情,但现在我需要用这个页面编写一个柏树测试,错误阻止了测试。
赛普拉斯有没有办法忽略这个错误?或者有没有办法从一开始就防止错误发生?RGBField 是否有一个标志来关闭对 jquery 的检查?
运行'django' in window
产生false
,运行django.jQuery
产生错误。运行'django' in window && django.jQuery
产生false
所以理论上应该采用第二个选项,当我在控制台中运行时它很好(但显然我错过了一些东西)。
编辑:
已安装应用程序列表:
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.humanize',
'whitenoise.runserver_nostatic',
'storages',
'django.contrib.staticfiles',
'django.contrib.flatpages',
'jquery',
'django.contrib.sites',
'django_activeurl',
'webpack_loader',
'widget_tweaks',
'argonauts',
'rest_framework',
'main',