Django teaches you how to master CKEditor in rich text editor

Source: Internet
Author: User
Tags install django pip install django
Recently, due to the need to use the rich text editor in djangoadmin, because I prefer the CKEditor rich text editor, so I have this article, the following article describes how to easily use the rich text editor CKEditor in django. For more information, see. Recently, due to the need to use the rich text editor in django admin, because I prefer the CKEditor rich text editor, so I have this article, the following article describes how to easily use the rich text editor CKEditor in django. For more information, see.

Preface

Django is an easy-to-use web framework. it is very convenient to use it to create a content-driven website (such as an independent blog. Unfortunately, django does not provide an official rich text editor, which happens to be an indispensable control in content-based website background management. Ckeditor is a javascript-based open-source web editor that is widely used. It can be combined with multiple programming languages, and python is no exception. This article describes how to use ckeditor perfectly in the django-based blog system.

Usage

1. Installation

pip install django-ckeditor

2. set INSTALLED_APPS in 'ckeditor' settings. py

3. because djang-ckeditor uses JQuery in the ckeditor-init.js file, you need to set CKEDITOR_JQUERY_URL in settings. py to specify the path of the JQuery library, for example:

CKEDITOR_JQUERY_URL ='https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js'

4. set STATIC_ROOT and runpython manage.py collectstatic, And merge the media resources required by CKEditor into the path specified by STATIC_ROOT.

STATIC_ROOT = os.path.join(BASE_DIR,'static/')

5,

From django. db import modelsfrom ckeditor. fields import RichTextFieldclass Blog (models. model): title = models. charField (max_length = 50, verbose_name = "title") content = RichTextField (blank = True, null = True, verbose_name = "content") def unicode (self): return self. name

Effect:

File Upload

1. add ckeditor_uploader to INSTALLED_APPS in settings. py.

2. CKEditor uses Django's storage API. by default, it uses Django's file storage and uses MEDIA_ROOT and MEDIA_URL. in py, you can also specify CKEDITOR_UPLOAD_PATH, which is located under MEDIA_ROOT:

MEDIA_URL = '/media/'MEDIA_ROOT = os.path.join(BASE_DIR,'media/')CKEDITOR_UPLOAD_PATH = 'uploads/'

3. add the CKEditor URL ing in the project's urls. py.

url(r'^ckeditor/', include('ckeditor_uploader.urls')),

If this parameter is not added, the following error may occur:

4. (optional) add CKEDITOR_IMAGE_BACKEND to settings. py to enable thumbnails, for example:

CKEDITOR_IMAGE_BACKEND = 'PIL'
from ckeditor_uploader.fields import RichTextUploadingFieldclass Post(models.Model): content = RichTextUploadingField()

Summary

The above is the detailed content that django teaches you to master the CKEditor method of rich text editor. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.