Add a django-ckeditor to your django admin and use it as a TextField

you have a rich text saved in your database and you want to make change to it and format the text the way you want to it apear like in your web-site ?

Aymane Talibi
3 min readSep 14, 2020

that’s actually easy with django-ckeditor

So, let’s do that :

first you have to follow the link : https://pypi.org/project/django-ckeditor/3.6.2.1/

a page like this will be appear :

You have firstly to get the latest version of this pluging, so click on the read button “ newer version available (*.*.*)”, then it will turn to a green button with the text : “ latest version ”

Now you have to copy the the install command generated :

We are done now with the website of ckeditor hihi, now go to your project folder and open the cmd, for example that’s mine :

Now paste the command copied in your cmd, and press enter, then you will get a success installation message.

Now you installed the plugin, you just have to define it in your djano project, so open your project folder in whatever IDE.

For me I want to add this plugin to this :

So, I have to go first to my settings.py and past the name of plugin with installed apps : ‘ckeditor’

Then, I have to go to my models.py file and import from ckeditor the RichTextField with adding ‘from ckeditor.fields import RichTextField’ on the top of the .py file and change body=models.TextField() with body=RichTextField(), the code look like :

Now we have to save the work and run the server and going to our administration account to find that we have the django-ckeditor added to our TextField()

Now We added the ckeditor to our django admin, It’s easy isn’t ?!
And we have to add only one more modification to make sure that our text will appear in the website correctly not as HTML text, so we have to go to our HTML and add a ‘|safe’ to the element that We want to display It.

Fine, all now is correctly done, enjoy to format your text and make sure to make your website more nice.

--

--