1👍
✅
I know it’s an old question, but it hasn’t been answered and it may help others…
Below are the steps I follow when using Ckeditor on django.
1.Add ‘ckeditor’ to installed apps on settings.py
2.Add ckeditor config variables in settings.py. (upload location and tools)
CKEDITOR_UPLOAD_PATH = MEDIA_ROOT
CKEDITOR_BASEPATH = os.path.join(STATIC_ROOT, "ckeditor/")
CKEDITOR_CONFIGS = {
'default': {
'toolbar': [
['Undo', 'Redo',
'-', 'Bold', 'Italic', 'Underline',
'-', 'Link', 'Unlink', 'Anchor',
'-', 'Format',
'-', 'SpellChecker', 'Scayt',
'-', 'Maximize',
'-', 'Language',
],
],
'height': '100%',
'width': '100%',
'toolbarCanCollapse': False,
},
'full': {
'toolbar': [
['Undo', 'Redo',
'-', 'Bold', 'Italic', 'Underline', 'NumberedList', 'BulletedList',
'-', 'Outdent', 'Indent', 'Blockquote', 'CreateDiv',
'-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock',
'-', 'TextColor', 'BGColor',
'-', 'Maximize', 'ShowBlocks', #'Image' ,
'-', 'Cut', 'Copy', 'Paste', 'PasteText',
],
['-', 'SpecialChar',
'-', 'Source',
],
[
'-', 'Styles', 'Format', 'Font', 'FontSize'
],
[
'-', 'BidiLtr', 'BidiRtl'
]
],
'width': '100%',
'height': '600px',
'toolbarCanCollapse': False,
},
'disable': {
'toolbar': [],
'width': '100%',
'height': '600px',
'toolbarCanCollapse': False,
},
}
3.Add ckeditor to the models
from django.db import models
from ckeditor.fields import RichTextField
class Article(models.Model):
content = RichTextField(default="")
4.Finally, the magic happens when you add ckeditor widget in a form:
from django import forms
from django.utils.translation import ugettext_lazy as _
from ckeditor.widgets import CKEditorWidget
from apps.articles.models import Article
class ArticleForm(forms.ModelForm):
content = forms.CharField(widget=CKEditorWidget(config_name='full'), label=_('Content'))
class Meta:
model = Article
Of course, don’t forget
python manage.py collectstatic
to get all static data to your static dir, and
python manage.py makemigrations model_name
python manage.py migrate model_name
to create the databases fields.
One more thing! Add this to the page head when the form is used in order to load the necessary scripts for ckeditor to work
{{ form_name.media }}
😉
Source:stackexchange.com