1

In a django application, target is to edit e-mail template in a WYSIWYG editor. Using CKEditor works fine, but images can only be included via URL, not via upload.

A similar question is asked here: Django-CKEditor Image Upload

What is not covered there is the case where a Form Field is used, not a Model Field. Also the accepted solution is not really explained.

Current code:

from django import forms
from crispy_forms.helper import FormHelper

class EmailConfirmationTemplateForm(forms.Form):
    def __init__(self, *args, **kwargs):
        self.email_template = kwargs.pop('email_template')
        kwargs.setdefault('initial', {})['email_template'] = self.email_template
        super(EmailConfirmationTemplateForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper(self)
        self.fields['email_template'] = forms.CharField(widget=CKEditorWidget())

Template code:

...
<form>
    {% csrf_token %}
    {% crispy form %}
</form>

Settings:

INSTALLED_APPS = [
    ...
    'ckeditor',
    'ckeditor_uploader',
    ...
]

CKEDITOR_UPLOAD_PATH = 'cke-uploads/'
CKEDITOR_IMAGE_BACKEND = 'pillow'

Question is: How to have the possibility to upload images in this WYSIWYG editor?

Version Info: django 1.8.16, django-ckeditor 5.2.2

Community
  • 1
  • 1
Davy
  • 1,720
  • 1
  • 19
  • 42

1 Answers1

1

Am not very sure about that django-version, but now ckeditor supports uploading picures by using its RichTextUploadingField. So for using it for models its quite simple. Go to your app_name/models.py and import RichTextUploadingField. Then instead of using something like:

article_content = models.TextField()

use this

article_content = models.RichTextUploadingField()
Mateo Hela
  • 19
  • 6