How to Ckeditor Image Upload in Django Python ?

Published On: 14/07/2022 | Category: Django Python

Hi Dev,

In this tutorial, I will show you how to multiple image upload in python django. This post will give you simple example of how to multiple image upload in python django app. We will look at example of how to multiple image upload in python django bootstrap. if you want to see example of how to multiple image upload in python django example then you are a right place.

So, CKEditor is a rich text WYSIWYG editor. This article shows how to add a RichTextUploading field to a model that enables all basic CKEditor features plus allows users to upload images.

Here i explained simply step by step example of how to multiple image upload in python django in database.

Step 1 : Create a Project

In this step, we’ll create a new django project using the django-admin. Head back to your command-line interface and run the following command:

django-admin startproject ckEditor
Step 2 : Create a App
python3 startapp core
Step 3 : Install Django-CKEditor Library

First of all we can install the django-ckeditor library. let us see how to use this library.

pip install django-ckeditor
Step 4 : Update

In this step we require to do two things in our file, One is to change the path of template look up directory. Second one is to configure our media folder. Add the below lines to your file:


Next, you need to add it in the file as follows:

import os


STATIC_URL = '/static/'

    os.path.join(BASE_DIR, "static"),

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


Let me one things clear in MEDIA_URL, you must add the first slash / because, without it, the images will not appear.

Step 5: Create a Model

In this step we will To represent our model in the admin interface, add this line in add the following code:

from django.db import models
from ckeditor_uploader.fields import RichTextUploadingField

class Blog(models.Model):
    title = models.CharField(max_length=100)
    content = RichTextUploadingField()
    def __str__(self):
        return self.title

After creating these model, you need to create migrations using the following command:

Step 6 : Create a Migrations
python makemigrations

After successfully run the above command go to the core/migrations/

# Generated by Django 3.2.3 on 2022-07-13 06:13

import ckeditor_uploader.fields
from django.db import migrations, models

class Migration(migrations.Migration):

    initial = True

    dependencies = [

    operations = [
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(max_length=100)),
                ('content', ckeditor_uploader.fields.RichTextUploadingField()),

Next, you need to migrate your database using the following command:

python migrate
Step 7 : Update the

In this step, we need to create the views for performing fetch record to the database.Open the core/ file and add:

from django.contrib import admin
from .models import *

# Register your models here.
Step 8 : Display Content of Editor on the Template

Next, to display the editor's content on an html page you need to do something like:

<!DOCTYPE html>


Step 9 : Creating Urls

In this section, we’ll create the urls to access our views.Go to the ckEditor/ file and update it as follows:

from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
    path('ckeditor/', include('ckeditor_uploader.urls')),

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Run the Server

In this step, we’ll run the local development server for playing with our app without deploying it to the web.

python runserver

Next, go to the http://localhost:8000/admin address with a web browser.

I Hope It will help you....