ckeditor
settings配置
############# CKEDITOR #############MEDIA_ROOT = os.path.join(BASE_DIR, 'media')CKEDITOR_UPLOAD_PATH = 'upload/'IMAGE_QUALITY = 40THUMBNAIL_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 modelsfrom ckeditor.fields import RichTextFieldfrom 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, includefrom django.contrib import adminfrom ckeditor_uploader import views as ck_viewsfrom app01 import viewsfrom django.conf import settingsfrom django.conf.urls.static import staticurlpatterns = [ 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 modelsadmin.site.register(models.Tag)