基于customizing CKEditor editor,我在settings.py中声明了一个自定义配置
CKEDITOR_CONFIGS = {
'awesome_ckeditor': {
'toolbar': 'Basic',
'toolbar_CustomToolbarConfig': [
{'name': 'clipboard', 'items': ['Bold', '-', 'Undo', 'Redo']},
{'name': 'paragraph', 'items': ['NumberedList', 'BulletedList', '-', 'BidiLtr', 'BidiRtl',
'-', 'spellchecker' ]},
],
},
}此配置在models.py中使用
description = RichTextField(config_name='awesome_ckeditor', blank=True)在html文件中,我以这种方式使用ckeditor:
<form action="{% url 'contact' %}" method="POST">
{% csrf_token %}
<div>
<textarea name="message"
id="message"
class="form-control"></textarea>
</div>
</form>
<script type="text/javascript" src="{% static "ckeditor/ckeditor-init.js" %}"></script>
<script type="text/javascript" src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script>
<script src="//cdn.ckeditor.com/4.15.0/full/ckeditor.js"></script>
<script>
CKEDITOR.replace( 'message');
CKEDITOR.config.allowedContent = true;
CKEDITOR.config.removeFormatAttributes = '';
</script>此配置不起作用。如何加载?
在声明此配置之前,我在管理面板内部和外部得到了不同的编辑器选项:
内部管理面板:

在它之外:

如何修复此配置,使所有页面都有相同的配置?
发布于 2020-12-04 04:40:41
试试这个:
CKEDITOR_CONFIGS = {
'default': {
'toolbar': 'Custom',
'toolbar_Custom':
[{'name': 'clipboard', 'items': ['Bold', '-', 'Undo', 'Redo']},
{'name': 'paragraph', 'items': ['NumberedList', 'BulletedList', '-', 'BidiLtr', 'BidiRtl', '-', 'spellchecker']}],
}
}检查器将查找admin的默认设置。
description = RichTextField(config_name='awesome_ckeditor', blank=True)并在settings.py中更新CKEDITOR_CONFIGS。
description = RichTextField(blank=True)但是你的settings中必须有default。
更新在看到op的答案后,op的答案将我指出了您的op代码中的另一个问题,我之前遗漏了这个问题。
前面,我没有注意到op正在使用js将ckeditor插入到message中。这不是django-ckeditor的预期用途。
在你的模型中,你有
description = RichTextField(blank=True)
# not need to put "config_name" beause it is set to "default"你应该做的是在你的模板中,使用{{ form}}代替。
确保在contact视图中有form。
<form action="{% url 'contact' %}" method="POST">
{% csrf_token %}
{{form.media}}
{{form}}
</form>删除以下内容:
<script>
CKEDITOR.replace( 'message');
CKEDITOR.config.allowedContent = true;
CKEDITOR.config.removeFormatAttributes = '';
</script>https://stackoverflow.com/questions/65128154
复制相似问题