gpt4 book ai didi

python - django 管理中的 CKEditor 配置

转载 作者:行者123 更新时间:2023-11-28 17:06:22 25 4
gpt4 key购买 nike

我需要在 Django 的管理面板中添加 richtextfield,所以我选择了 CKEditor,但是我在配置方面遇到了一些问题:

当我出于某种原因尝试在 django 管理面板(使用 Enter 键)编辑器中移动一行时,将 p 标记添加到我的文本中,我不需要(我的意思是在管理编辑器中,不在模板中)。我可以以某种方式停用它吗?或者替换成br标签?

enter image description here

我使用 CKEditor 的默认配置。

设置.py

CKEDITOR_CONFIGS = {
'awesome_ckeditor': {
'toolbar': 'Basic',
},
}

模型.py

class Section_1(models.Model):
order = models.IntegerField(blank=True, default=0)
picture = models.ImageField(blank=True)
text = RichTextField(max_length=200, blank=True)
ytlink = models.URLField(blank=True)

def __str__(self):
return self.text

class Meta:
verbose_name = 'Секция 1'
verbose_name_plural = 'Секция 1'

在模板中的集成:

<div class="main-screen__middle-title">
{% for sec_1 in sec_1 %}
{% if sec_1.order == 1 %}
<h4 class="main-screen__middle-title_active" data-mScreen="mscreen{{
sec_1.order }}">{{ sec_1.text }}</h4>
{% else %}
<h4 data-mScreen="mscreen{{ sec_1.order }}">{{ sec_1.text }}</h4>
{% endif %}
{% endfor %}

</div>

因此,当我打开没有 {{ sec_1.text| 的模板时安全}}我看到了这个:

enter image description here

如果我使用它,CKEditor 会忽略 h4 标签:

enter image description here

问题是:

1) 如何在管理面板中删除自动添加 'p'

2) 如果我对我的变量使用 |safe,如何让它不忽略外部 html 标签?

最佳答案

如果您不想用任何东西包裹文本,您可以选择插入换行符标记,因为默认情况下它使用 p 标记进行换行。

config.enterMode = CKEDITOR.ENTER_P;

You need to add below line in config.js file for CKEditor:

CKEDITOR.editorConfig = function (config)
{
config.enterMode = CKEDITOR.ENTER_BR;

...
};

否则如果你想用 div 标签包装,

config.enterMode = CKEDITOR.ENTER_DIV;

关于python - django 管理中的 CKEditor 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50709813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com