Uncaught ReferenceError: django is not defined(未捕获的 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>
同时检查 ModelAdmin
的 media
属性.
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 未定义
基础教程推荐
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01