How will I add css with Django Ckeditor?

750 Views Asked by At

I used django-ckeditor, It's working perfectly. But problem is, I couldn't add CSS. Even it ruined the template design. Even jQuery also not working in template. I actually would like to responsive the field so that in the mobile works perfectly. Now how can I do it?

forms.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;'}),
        }

templates:

    <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>

details template:

    <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>
1

There are 1 best solutions below

4
kimnluna On

This should solve your concern. Allowed Content defines which HTML elements, attributes, styles, and classes are allowed. To get allowedContent to work, disable stylesheetparser plugin.

You can place this within your settings.py file.

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

To learn more, you can find the documentation here.