Implementing RichText Editor (CKEditor) in Django for an E-commerce Website | EP. 19 by Desphixs

Posted by

RichText Editor (CKEditor) in Django

RichText Editor (CKEditor) in Django

Welcome to Episode 19 of our Django E-commerce Website series on Desphixs!

Adding CKEditor to Django

If you want to add a RichText Editor to your Django E-commerce website, CKEditor is a great choice. It is a flexible and customizable text editor that allows users to easily create and edit content.

To add CKEditor to your Django project, you first need to install the django-ckeditor package using pip:

pip install django-ckeditor

Next, you need to add ‘ckeditor’ to your INSTALLED_APPS in your settings.py file:

INSTALLED_APPS = [
    ...
    'ckeditor',
]

Using CKEditor in Django Templates

Once CKEditor is installed, you can use it in your Django templates by adding the following code:

{% load static %}
{{ form.media }}
{{ form.content|safe }}

Make sure to load the CKEditor media files using the form.media tag, and use the |safe filter to render the HTML content properly.

Customizing CKEditor in Django

CKEditor is highly customizable, allowing you to change its appearance and functionality to fit your website’s needs. You can customize CKEditor by creating a custom CKEditor configuration in your settings.py file:

CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'Custom',
        'toolbar_Custom': [
            {'name': 'styles', 'items': ['Format', 'Font', 'FontSize']},
            {'name': 'colors', 'items': ['TextColor']},
            {'name': 'basicstyles', 'items': ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript']},
            {'name': 'paragraph', 'items': ['NumberedList', 'BulletedList', '-', 'Blockquote']},
            {'name': 'links', 'items': ['Link', 'Unlink']},
            '/',
            {'name': 'clipboard', 'items': ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo']},
            {'name': 'editing', 'items': ['Find', 'Replace']},
            {'name': 'tools', 'items': ['Maximize']},
        ],
        'height': 300,
    }
}

In this configuration, we have customized the toolbar, added additional styling options, and set the default height of the editor to 300px. You can further customize CKEditor by exploring the available options in the official documentation.

Conclusion

Adding a RichText Editor like CKEditor to your Django E-commerce website can enhance the user experience and make it easier for users to create and edit content. By following the steps outlined in this article, you can integrate CKEditor into your Django project and customize it to suit your specific requirements.

We hope you found this tutorial helpful! Stay tuned for more episodes of our Django E-commerce Website series on Desphixs.

0 0 votes
Article Rating
8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@user-gg1pf7tt6f
2 months ago

Hey Destiny,
Seems your package doesn't have the prism js and CSS files. Can you add them to the drive, please?

@solijonovasadbek4552
2 months ago

perfect

@ajdark2512
2 months ago

Hey bro,
Can we crop and upload images on admin dashboard using ckeditor or is there any other method…

@dovranjacobson628
2 months ago

great job done, keep on Desphixs! Will there be a tutorial about multilanguage? Cuz in template we can choose language on top right corner.

@ingafter6335
2 months ago

Hi Desphixs,
I could made it following your example, but without html and copy on the top-right corner ..
It makes me a lot of happy ..😊

@ingafter6335
2 months ago

Hi Desphixs

Can you please shared for us the
– default.min.css,
– hljs.initHighlightingOnLoad(),
– highlight.min.js,
– prism.js, and
– prism.css

that you just added to product-detail page?

Thanks for your kindness 🙏

@BiseshAdhikari
2 months ago

Hello, @desphixs, great work. Your tutorials are helpful to me. I want to request one necessary topic which almost none has made a tutorial on. Can you please make a dynamic multistep form using Django? It would be really helpful for newbies like me. Please take this into consideration, there is almost not a tutorial about this topic.

@ingafter6335
2 months ago

Please show us how to use tinymice editor ..
It will give us options which one to use: tinymice or ckeditor.
Thanks