未捕获的ReferenceError:未定义django

时间:2022-04-16 18:29:28

I'm trying to use the Admin Widgets with a couple of DateField on my formulary but only the first of them gets the widget displayed correctly, for the other one I get an error:

我正在尝试在我的处方集上使用带有几个DateField的Admin Widgets,但只有第一个才能正确显示小部件,而另一个我得到一个错误:

DateTimeShortcuts.js:205 Uncaught ReferenceError: django is not defined

DateTimeShortcuts.js:205未捕获的ReferenceError:未定义django

(The line indicated is:

(所示的线是:

django.jQuery(document).bind('keyup', function(event) { 

)

Here's my template head:

这是我的模板头:

<head>
{% load adminmedia  %}
<link rel="stylesheet" href="/static/css/main.css" />
<script type="text/javascript" src="/admin/jsi18n/"></script>
<script type="text/javascript" src="/static/admin/js/core.js"></script>
<script type="text/javascript">
    window.__admin_media_prefix__ = "{% filter escapejs %}{% admin_media_prefix %}{% endfilter %}";
</script>
<link rel="stylesheet" type="text/css" href="/static/admin/css/forms.css"/>
<link rel="stylesheet" type="text/css" href="/static/admin/css/base.css"/>
<!-- <link rel="stylesheet" type="text/css" href="/static/admin/css/global.css"/> -->
<link rel="stylesheet" type="text/css" href="/static/admin/css/widgets.css"/>
{{ form.media }}...

My model fields:

我的模型字段:

start_date = models.DateField()
end_date = models.DateField()

And my form class:

我的表格类:

class UserForm(ModelForm):
    start_date = forms.DateField(
        widget=widgets.AdminDateWidget
        )
    end_date = forms.DateField(
        widget=widgets.AdminDateWidget
        )
    class Meta:
        model = User

I guess it some kind of rendering rule but I'm totally confused. Any help is welcome!

我猜它是某种渲染规则,但我完全糊涂了。欢迎任何帮助!

2 个解决方案

#1


29  

django.jQuery is defined in django/contrib/admin/static/admin/js/jquery.init.js and relies on django/contrib/admin/static/admin/js/jquery.js. You need to load those js files in your template directly

django.jQuery在django / contrib / admin / static / admin / js / jquery.init.js中定义,并依赖于django / contrib / admin / static / admin / js / jquery.js。您需要直接在模板中加载这些js文件

<script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/admin/js/jquery.init.js"></script>

Or include those files in your form media

或者在表单媒体中包含这些文件

Also check the media property of ModelAdmin.

还要检查ModelAdmin的media属性。

#2


0  

I solve it by this way:

我通过这种方式解决它:

class CustomIndexDashboard(Dashboard):
    class Media:
        js = ('admin/js/vendor/jquery/jquery.min.js', 'admin/js/jquery.init.js')

#1


29  

django.jQuery is defined in django/contrib/admin/static/admin/js/jquery.init.js and relies on django/contrib/admin/static/admin/js/jquery.js. You need to load those js files in your template directly

django.jQuery在django / contrib / admin / static / admin / js / jquery.init.js中定义,并依赖于django / contrib / admin / static / admin / js / jquery.js。您需要直接在模板中加载这些js文件

<script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/admin/js/jquery.init.js"></script>

Or include those files in your form media

或者在表单媒体中包含这些文件

Also check the media property of ModelAdmin.

还要检查ModelAdmin的media属性。

#2


0  

I solve it by this way:

我通过这种方式解决它:

class CustomIndexDashboard(Dashboard):
    class Media:
        js = ('admin/js/vendor/jquery/jquery.min.js', 'admin/js/jquery.init.js')