jph
jph

Reputation: 367

Adding CKEditor to Django project

Could someone please guide me in the proper direction to install CKEditor in my Django project? I'm very new at this, so the more thorough of a explanation, the much more helpful it will be for me.

I found this link, but it isn't working very well for me: http://docs.ckeditor.com/#!/guide/dev_installation.

Thank you very much!

Upvotes: 1

Views: 5299

Answers (2)

django-renjith
django-renjith

Reputation: 4000

pip install ckeditor
  1. Add -ckeditor- in setting of your project [installed apps]

Admin CK Editor for video embedding

CKEDITOR_UPLOAD_PATH = root('uploads')
CKEDITOR_RESTRICT_BY_USER = True

CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'Advanced',
        'width': 758,
        'height': 300,
    },
}

Admin CK Editor for video embedding

  1. Create a folder uploads inside the project

  2. Add this url in your main urls.py

    url(r'^ckeditor/', include('ckeditor.urls')),
    
  3. Add this in to your models.py

    from ckeditor.fields import RichTextField
    content = RichTextField(verbose_name='BlogContent',null=True,blank=True)
    

Make sure do python manage.py collectstatic before running your project.

Upvotes: 0

ruddra
ruddra

Reputation: 51978

There is another way of integrating CKeditor to Django by using Javascript version of CKeditor.

Download ckeditor from http://ckeditor.com/download and extract the zip file, put the unzipped folder in static root. add ckeditor static files to your template like:

<script src="{{STATIC_URL}}ckeditor/ckeditor.js"></script>

In your form, add html class like this:

class SomeForm(forms.Form):

    text = forms.CharField(widget = forms.Textarea(attr={'class':'richtexteditor'})

And to make this rich text editor visible, add the following line your template:

<script>
  CKEDITOR.replace( '.richtexteditor' );
</script>

Upvotes: 6

Related Questions