涉及到的文件会在文章结尾给出下载地址!
1) 将 ckeditor 放在某个位置,只要你的settings可以搜索到,比如,我放在目录第一层,setting设置如下:
INSTALLED_APPS = ( 'ckeditor', )2) 将静态文本放在static下。
目录结构应该为 :
--static/
--ckeditor/
----ckeditor
----css
3)settings里设置样式:
CKEDITOR_CONFIGS = { 'default': { 'toolbar':[ ['Source','-','Save','NewPage','Preview','-','Templates'], ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print','SpellChecker','Scayt'], ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], ['Form','Checkbox','Radio','TextField','Textarea','Select','Button', 'ImageButton','HiddenField'], ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['Link','Unlink','Anchor'], ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'], ['Styles','Format','Font','FontSize'], ['TextColor','BGColor'], ['Maximize','ShowBlocks','-','About'] ], 'width': 650, 'height': 200, 'toolbarCanCollapse': False, }, }4) 模型里的相关代码:
from ckeditor.widgets import CKEditor ........ class TextEntry(EntryType): ..... class AdminForm(EntryType.AdminForm): content = forms.CharField(widget=CKEditor(),label='内容:')注意,这是我的代码,里面的 EntryType 只是我的一个父类模型。
5) template 文件里头文件上 加上
<script type="text/javascript" src="{{ MEDIA_URL }}ckeditor/ckeditor/ckeditor.js"></script>然后代码里直接 {{ form }},懂Django表单的,应该知道这句话的意思!
==============================================================================
如果这样还出现问题,看看是不是你的 {{ MEDIA_URL }} 路径问题了。 如果不是,贴出来探讨下!
下载地址
转载于:https://www.cnblogs.com/timest/archive/2012/05/03/2480014.html