未捕获的 ReferenceError:django 未定义

Uncaught ReferenceError: django is not defined(未捕获的 ReferenceError:django 未定义)

本文介绍了未捕获的 ReferenceError:django 未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的公式中使用带有几个 DateField 的管理小部件,但只有第一个可以正确显示小部件,而另一个我收到错误:

<块引用>

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

(指示的行是:

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

)

这是我的模板头:

{% 加载管理媒体 %}<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><脚本类型="文本/javascript">window.__admin_media_prefix__ = "{% filter escapejs %}{% admin_media_prefix %}{% endfilter %}";</脚本><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 }}...

我的模型字段:

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

还有我的表单类:

类 UserForm(ModelForm):start_date = forms.DateField(小部件=小部件.AdminDateWidget)end_date = forms.DateField(小部件=小部件.AdminDateWidget)元类:模型 = 用户

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

解决方案

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>

或将这些文件包含在您的表单媒体中p>

同时检查 ModelAdminmedia 属性.

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:

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

(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!

解决方案

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

<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.

这篇关于未捕获的 ReferenceError:django 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:未捕获的 ReferenceError:django 未定义

基础教程推荐