CKEditor:在DjangoCMS中配置允许的内容

时间:2014-10-23 09:55:25

标签: javascript python ckeditor django-cms

我在配置CKeditor时遇到问题。我想制作"如何允许一切除外......"在CKEditor中的方案,以及在docs中写的,我需要在config中写:

config.allowedContent = {
    $1: {
        // Use the ability to specify elements as an object.
        elements: CKEDITOR.dtd,
        attributes: true,
        styles: true,
        classes: true
    }
};
config.disallowedContent = 'script; *[on*]';

但是由于用python编写的CKEditor配置,我不能简单地写CKEDITOR.dtd。那么,有没有解决方案呢?

1 个答案:

答案 0 :(得分:0)

在许多情况下,使用settings.py中的以下声明添加其他允许的标记或属性可能就足够了:

TEXT_ADDITIONAL_TAGS = ('iframe',)
TEXT_ADDITIONAL_ATTRIBUTES = ('scrolling', 'allowfullscreen', 'frameborder')

当然,您需要根据自己的需要进行调整。

如果你真的想要“只允许一切”逻辑,那么你必须为Django CMS用来清理HTML的后端编写自己的解析器。这意味着,在前端编辑器上,您可能希望使用选项

关闭所有卫生设施
CKEDITOR_SETTINGS = {
    ...,
    'basicEntities': False,
    'entities': False,
    ...
}

在后端,documentation表示您可以编写符合您要求的自己的python解析器。我没试过这个,所以如果有任何帮助,请告诉我。