1. 安装 django-ckeditor
pip install django-ckeditor
3. 添加 CKEDITOR_UPLOAD_PATH 的配置到 settings.py
MEDIA_URL = "/media/" MEDIA_ROOT = os.path.join(BASE_DIR, "media")
CKEDITOR_UPLOAD_PATH = "images"
4.在 Project 的 urls.py 文件中添加 ckeditor 的 url
url(r'^ckeditor/', include('ckeditor_uploader.urls')),
from django.conf import settings from django.conf.urls.static import static urlpatterns = [ # ... the rest of your URLconf goes here ... ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
5.在 models.py 中使用from ckeditor_uploader.fields import RichTextUploadingField class Example(models.Model): body = RichTextUploadingField('rich text field')
6.在 templates 中使用内容{{ example.body | safe }}