【问题标题】:How will I add css with Django Ckeditor?如何使用 Django Ckeditor 添加 css?
【发布时间】:2022-08-02 14:14:18
【问题描述】:

我使用了django-ckeditor,它运行良好。但问题是,我无法添加 CSS。甚至它破坏了模板设计。甚至 jQuery 也不能在模板中工作。现在我该如何解决这些问题?

表格.py:

from django import forms
from .models import Products
from django.forms import ModelForm
from ckeditor.fields import RichTextField

class add_product_info(forms.ModelForm):
    product_desc = RichTextField()

    class Meta:
        model = Products
        fields = (\'product_desc\')

        labels = {
            \'product_desc\':\'Description\',
        }

        widgets = {
            \'product_desc\':forms.Textarea(attrs={\'class\':\'form-control\', \'style\':\'font-size:13px;\'}),
        }

模板:

    <form action=\"\" method=\"POST\" class=\"needs-validation\" style=\"font-size: 13px;\" novalidate=\"\" autocomplete=\"off\" enctype=\"multipart/form-data\">
    {% csrf_token %}
    {{form.media}}
    {{ form.as_p }}
    <div class=\"d-flex align-items-center\">
        <button type=\"submit\" class=\"btn btn-outline-dark ms-auto\" style=\"font-size:13px;\">Add</button>
    </div>
    
    </form>

详细模板:

    <p class=\"item_desc_container text-center text-md-center text-lg-start descriptions poppins_font\" style=\"font-size: 15px;\">
{{ quick_view.product_desc|safe }}
    </p>

    标签: django django-ckeditor


    【解决方案1】:

    这应该可以解决您的担忧。允许的内容定义了允许的 HTML 元素、属性、样式和类。要让 allowedContent 工作,请禁用 stylesheetparser 插件。

    你可以把它放在你的 settings.py 文件中。

       CKEDITOR_CONFIGS = {'default': {
    'removePlugins': 'stylesheetparser',
    'allowedContent': True,},}
    

    要了解更多信息,您可以找到文档here

    【讨论】:

      猜你喜欢
      • 2022-06-30
      • 1970-01-01
      • 2011-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-31
      • 1970-01-01
      • 2019-06-29
      相关资源
      最近更新 更多