ckeditor
settings配置
############
# CKEDITOR #
############
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
CKEDITOR_UPLOAD_PATH = 'upload/'
IMAGE_QUALITY = 40
THUMBNAIL_SIZE = (300, 300)
CKEDITOR_IMAGE_BACKEND = "pillow"
CKEDITOR_CONFIGS = {
'default': {
'skin': 'moono-lisa', # 主题,可选:moono-lisa moono kama
# 'uiColor': '#AADC6E',
# 高度
'height': 600,
# 宽度
'width': "100%",
# 文件上传路径
'filebrowserUploadUrl': '/ckeditor/upload/',
# 工具栏
'toolbar': (
['Format', ],
['Bold', 'Italic', 'Underline', 'Strike', '-'],
['TextColor', 'BGColor'],
['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
# ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Print', 'SpellChecker', 'Scayt'],
['Undo', 'Redo', '-', 'Find', 'Replace', '-',
'RemoveFormat', '-', 'Maximize', '-', "CodeSnippet", 'Subscript', 'Superscript'],
# ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton'],
['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'],
['Link', 'Unlink', 'Anchor'],
['Image', 'Flash', '-', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak'],
['div', 'Source', '-', 'Preview', '-', 'Templates'],
),
# 扩展插件
'extraPlugins': ','.join([
'codesnippet', # 代码
# 'imagepaste',
'uploadimage', # 上传图片
'image2', # 粘贴式上传图片
# 'video',
# 'html5video',
]),
}
}
models
from django.db import models
from ckeditor.fields import RichTextField
from ckeditor_uploader.fields import RichTextUploadingField
# Create your models here.
class Tag(models.Model):
tag_type_choices = ((0, "用户注册标签"), (1, "文章标签"),)
tag_type = models.SmallIntegerField(default=0)
name = RichTextUploadingField()
order = models.SmallIntegerField(verbose_name="用于排序字段", default=0)
date = models.DateTimeField(auto_now_add=True)
class Meta:
db_table = "api_tag"
路由设置
from django.conf.urls import url, include
from django.contrib import admin
from ckeditor_uploader import views as ck_views
from app01 import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^make/', views.demo),
# `ck-editor` 示例
url(r'^ckeditor/', include('ckeditor_uploader.urls')),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
admin中使用
from django.contrib import admin
# Register your models here.
from app01 import models
admin.site.register(models.Tag)