1

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

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I actually would like to responsive the field so that in the mobile works perfectly
You would need CSS to make your field responsive. By allowing the configuration above, CKeditor will allow you to add styles/classes. Does that answer your question?
how can I allow the configuration so that I can use CSS for responsiveness?
With the settings above, it's already allowed. All you have to do is add the classes in the editor itself; click on "Source" in the editor to ad d classes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.