Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django ckeditor image upload

I'm using Django-ckeditor in my website.

I'm especially using

RichTextUploadingField()

in my model. and other option just works fine, except image upload.

1. Error Message

I'm getting an error message of

"Incorrect Server Response" and especially, chrome devtools indicates that


ckeditor.js:21 [CKEDITOR] Error code: filetools-response-error.

ckeditor.js:21 [CKEDITOR] For more information about this error go to https://docs.ckeditor.com/ckeditor4/docs/#!/guide/dev_errors-section-filetools-response-error


2. Guess

I have tried uploading images using ckeditor in my admin page,

authorized as superuser in django, it works.

However, logged in as the normal user account, I've tried the same thing, but it does not work.

So my guess is it has some kind of authorization problem. But I can't figure out where to start debugging in my django-ckeditor.

What things should I be checking? Thanks in advance.

like image 968
dongmin kim Avatar asked Sep 12 '25 20:09

dongmin kim


2 Answers

This is happening because the default urls are decorated with @staff_member_required(https://github.com/django-ckeditor/django-ckeditor/blob/master/ckeditor_uploader/urls.py). To avoid this, instead of including the urls like so url(r'^ckeditor/', include('ckeditor_uploader.urls')) you could define them one by one in your urls.py with the login_required decorator:

from django.conf.urls import url
from django.contrib.auth.decorators import login_required

from ckeditor_uploader import views

urlpatterns = [
     .....your other urls
    url(r'^ckeditor/upload/', login_required(views.upload), name='ckeditor_upload'),
    url(r'^ckeditor/browse/', never_cache(login_required(views.browse)), name='ckeditor_browse'),
]

Like this you are limiting the uploads to all users that are logged in.

like image 74
Kristiyan Gospodinov Avatar answered Sep 14 '25 11:09

Kristiyan Gospodinov


Add following imports in the project urls.py:

from django.contrib.auth.decorators import login_required
from django.views.decorators.cache import never_cache
from ckeditor_uploader import views as ckeditor_views

Replace the following row in the urls.py:

path('ckeditor/', include('ckeditor_uploader.urls')),

with

path('ckeditor/upload/', login_required(ckeditor_views.upload), name='ckeditor_upload'),
path('ckeditor/browse/', never_cache(login_required(ckeditor_views.browse)), name='ckeditor_browse'),
like image 45
Harman Kibue Avatar answered Sep 14 '25 11:09

Harman Kibue