CKEditor

DJANGO


1. How to adjust size of image loaded.

https://www.tutorialfor.com/questions-49701.htm

<style>
  img {
  max-width: 100%;
  height: auto;
}
</style>

 

2. How to rename file name of image uploaded.

/media/uploads/2020/12/07/image_jDrE23V.png

Create a new file utils.py in the same folder as setting.py.

In setting.py add the following

/media/uploads/2020/12/07/image_mQ9TmIm.png

/media/uploads/2020/12/07/image_xz6gKvo.png

Add the logic in the utils.py function.

 

3. Serve images in development server.

urls.py

from django.contrib import admin
from django.urls import path , include
from userguide import views
from django.conf.urls import url
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views.static import serve

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home , name='home'),
    url(r'^ckeditor/', include('ckeditor_uploader.urls')),
]
# serving media files only on debug mode
if settings.DEBUG:
    urlpatterns += [
        url(r'^(?P<path>.*)$', serve, {
            'document_root': settings.MEDIA_ROOT
        }),
    ]
setting.py

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

from sap_lib import utils

ckeditor_settings = {
    'config.disablenativespellchecker': False,
}
CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDITOR_IMAGE_BACKEND = "pillow"
CKEDITOR_BROWSE_SHOW_DIRS = True
CKEDITOR_RESTRICT_BY_DATE = False
CKEDITOR_FILENAME_GENERATOR = 'sap_lib.utils.get_filename'

Files are uploaded in main project folder. Folder Name uploads

            Related
CKEditor