Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django-ckeditor failing due to template path problem

I just added django-ckeditor to my django project by installing it:

pip install django-ckeditor

adding it to INSTALLED_APPS, adding the upload path:

CKEDITOR_UPLOAD_PATH = "ckeditor_uploads/"

run manage.py collecstatic which only added two files, and adding the URLs to my url.py:

url(r'^ckeditor/', include('ckeditor_uploader.urls')),

I'm not 100% sure if I'm not missing something there.

Then I created a very simple model that looks like this:

class BlogPost(models.Model):
    title = models.CharField(max_length=255, blank=False, null=False)
    body = RichTextField(blank=False, null=False)

When I try to add a new record on the admin tool I get this error:

TemplateDoesNotExist at /admin/core/blogpost/add/

ckeditor/widget.html

The template loader postmortem looks like this:

Template-loader postmortem
Django tried loading these templates, in this order:

Using engine django:

django.template.loaders.filesystem.Loader: C:\Users\pupeno\projectx\venv\lib\site-packages\django\forms\templates\ckeditor\widget.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\pupeno\projectx\core\templates\ckeditor\widget.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\pupeno\projectx\venv\lib\site-packages\django\contrib\admin\templates\ckeditor\widget.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\pupeno\projectx\venv\lib\site-packages\django\contrib\auth\templates\ckeditor\widget.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\pupeno\projectx\venv\lib\site-packages\rest_framework\templates\ckeditor\widget.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\pupeno\projectx\venv\lib\site-packages\reversion\templates\ckeditor\widget.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\pupeno\projectx\venv\lib\site-packages\colorfield\templates\ckeditor\widget.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\pupeno\projectx\venv\lib\site-packages\ckeditor_uploader\templates\ckeditor\widget.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\pupeno\projectx\venv\lib\site-packages\django_extensions\templates\ckeditor\widget.html (Source does not exist)

The line before the last one is relevant, it's trying to load ckeditor/widget.html from ckeditor_uploader but widget.html is present in ckeditor, not ckeditor_uploader:

enter image description here

Any ideas what's going on here?

I also tried turning the field into a RichTextUploadingField, but I've got the same error.

like image 839
pupeno Avatar asked Feb 19 '19 14:02

pupeno


3 Answers

The problem was that I added ckeditor_uploader and not ckeditor to the installed apps.

like image 136
pupeno Avatar answered Oct 27 '22 00:10

pupeno


Even I faced the same issue. Please follow my steps. it will work for me as well as many of my friends also.

Remember it will also work for production level as i hosted many django application in online.

pip install django-ckeditor

after

step 1: write inside models.py

from ckeditor.fields import RichTextField
class BlogPost(models.Model):
    title = models.CharField(max_length=255, blank=False, null=False)
    body = RichTextField(blank=False, null=False)

step 2: run command python manage.py makemigrations

step 3: run command python manage.py migrate

step 4: write in admin.py

from .models import BlogPost
admin.site.register(BlogPost)

step 4: I added "ckeditor" in installed_apps of settings.py.

step 5: run command python manage.py collectstatic

It will ask you to overrite Existing files and type yes

make sure your directory structure look like

make sure your directory structure look like

step 6: Copy ckeditor folder in root static folder where your control panel looks for

In my case i have to copy ckditor folder in another called public_html

I coppied ckeditor folder in public_html/static/

enter image description here

All done

like image 41
Subhransu Das Avatar answered Oct 26 '22 23:10

Subhransu Das


You need both apps in INSTALLED_APPS:

INSTALLED_APPS = [
  ...
  'ckeditor',
  'ckeditor_uploader'
  ...
]
like image 29
Roberth Solís Avatar answered Oct 26 '22 23:10

Roberth Solís