Install CKEditor
Download the CKEditor here. Place the CKEditor source in such a spot that the static web server can serve it. In my case I have created a media directory under the document root of the web static web server and then placed the CKEditor files in a directory ckeditor. Thus I can access the ckeditor.js like this http://localhost/media/ckeditor/ckeditor.js.
Update the MEDIA_URL = 'http://localhost/media/' in the settings.py of your django project.
My sample model is very simple and looks like this:
from django.db import modelsThe magic happens in the custom model admin form. The for for my sample model looks like this:
class SampleModel(models.Model):
title = models.CharField(max_length=50)
text = models.TextField()
def __unicode__(self):
return self.title
from sampleapp.models import SampleModelThe important things to notice is that I add class attribute to the textarea widget. When ckeditor then satrt up it knows to replace any textareas with the ckeditor code.
from django.contrib import admin
from django import forms
from django.db import models
class SampleModelAdmin(admin.ModelAdmin):
formfield_overrides = { models.TextField: {'widget': forms.Textarea(attrs={'class':'ckeditor'})}, }
class Media:
js = ('ckeditor/ckeditor.js',) # The , at the end of this list IS important.
admin.site.register(SampleModel,SampleModelAdmin)
The last thing to notice is the the media location is relative to the MEDIA_URL since there is no preceding /.
That's it.
Her is the sample application: django-ckeditor.zip. Or you can get is directly from the subversion repository:
svn checkout http://johanscode.googlecode.com/svn/devblog/django/ckeditor johanscode-read-only
Great Post! - Very well-defined example. Thank you!
ReplyDeletethanks, very clear and simple!
ReplyDeleteReally cool, just what I was looking for!
ReplyDeleteIs it possible to integrate CKEditor's image uploading capabilities to django?
that's great, but... the editor now goes off the page. this is in the default admin page in both Firefox 3.5.7 and Chrome 4.0b on Snow Leopard.
ReplyDeletethat's great, but... the editor now goes off the page. this is in the default admin page in both Firefox 3.5.7 and Chrome 4.0b on Snow Leopard.
ReplyDeleteI have the same issue. Ckeditor field goes off the right side of the page. Tried setting cols and style/width on the textarea without success.
ReplyDeleteAdd this at the end of your /media/ckeditor/contents.css
ReplyDeletefieldset div.form-row div span.cke_skin_kama {
border: 0;
padding: 0 !important;
float: left;
}
Remember to use it too
class Media:
css = {
'all': ('/media/ckeditor/contents.css',)
}
Nice Tutorial.
ReplyDeleteTip of ayeowch are amazing too.
Very simple!
ReplyDeleteI like it!
Thanks..
Very helpful, thanks!
ReplyDeleteits not right solution
ReplyDeletefirst make module files.py
from django.db import models
from django import forms
class CKField(models.Field):
def formfield(self, **kwargs):
defaults = {'form_class': forms.CharField, 'widget': forms.Textarea(attrs={'class':'ckeditor'})}
defaults.update(kwargs)
return super(CKField, self).formfield(**defaults)
in models:
import fields
and in class
description = fields.CKField()
in admin.py in class add
assets imports:
class Media:
js = ('/static/ckeditor/ckeditor.js',)
css = {'all': ('/static/ckeditor/skin/kama/contents.css',)}
How can I integrate these settings in django ckeditor?
ReplyDeleteindent : false,
breakBeforeOpen : true,
breakAfterOpen : false,
breakBeforeClose : false,
breakAfterClose : true
mmorpg oyunlar
ReplyDeleteinstagram takipçi satın al
tiktok jeton hilesi
TİKTOK JETON HİLESİ
antalya saç ekimi
referans kimliği nedir
İnstagram Takipçi Satın Al
metin2 pvp serverlar
takipçi
Smm Panel
ReplyDeletesmm panel
iş ilanları
İnstagram takipçi satın al
HİRDAVATCİ
www.beyazesyateknikservisi.com.tr
Servis
tiktok jeton hilesi
çekmeköy beko klima servisi
ReplyDeletependik toshiba klima servisi
pendik beko klima servisi
tuzla alarko carrier klima servisi
tuzla daikin klima servisi
ataşehir beko klima servisi
maltepe lg klima servisi
kadıköy lg klima servisi
maltepe alarko carrier klima servisi