曾经被富文本编辑器的配置搞的很头疼,后来发现django下有一款配置十分简单的富文本,整理一下配置过程。
安装
pip install django-ckeditor
settings配置
在其中加入这两个
INSTALLED_APPS = [
'ckeditor',
'ckeditor_uploader']
确保media路径配置好,ckeditor的上传路径在media下,我的配置也是就在media/upload中
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media_cdn')
CKEDITOR_UPLOAD_PATH = 'upload/'
urls
为ckeditor设置url
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'ckeditor/', include('ckeditor_uploader.urls'))
]
models
from django.db import models
from ckeditor_uploader.fields import RichTextUploadingField
class Post(models.Model):
content = RichTextUploadingField(null=True, blank=True)
到此打开后台就可以看到这个界面了