我想在我的一个模型字段中使用FilerImageField
,并希望用户在管理区域之外进行编辑,但当我尝试加载它时,小部件无法正常工作,在浏览器控制台中,我得到生成的javascript中的错误:
Uncaught TypeError: Cannot read property 'jQuery' of undefined
在这里:
<script type="text/javascript" id="id_featured_image_javascript">
django.jQuery(document).ready(function(){
var plus = django.jQuery('#add_id_featured_image');
if (plus.length){
plus.remove();
}
// Delete this javascript once loaded to avoid the "add new" link duplicates it
django.jQuery('#id_featured_image_javascript').remove();
});
</script>
我的模型中的字段定义如下:
article_image = FilerImageField(db_column="ARTICLE_IMAGE",
verbose_name=_('Article Image'),
related_name='IPP_ARTICLE_IMAGE')
该字段如下所示:
你知道为什么我不能在管理员之外使用这个字段小工具吗?我需要为此设置一些配置吗?
谢谢您:)
发布于 2017-11-21 10:11:12
首先,在html文件中添加{{ form.media }}
,紧跟在标记<form>
和{% csrf_token %}
之后。然后扩展forms.py的ModelForm
中的媒体类,如SteinRobert在Github问题上所解释的:https://github.com/divio/django-cms/issues/6028。它工作得很完美!谢谢Stein!
https://stackoverflow.com/questions/38512225
复制