您的位置:首页 > 编程语言 > Go语言

【Django基础入门】Ckeditor Wins7下图片上传及显示的路径问题

2012-07-10 09:39 645 查看
1:在 virtualenv 库里 安装 django-ckeditor

      F:\workspace\fx_lib 是我的 第三方库的路径,也可用  pip install django-ckeditor 进行安装

pypm -E F:\workspace\fx_lib install django-ckeditor


2:设置 settings.py

CKEDITOR_MEDIA_PREFIX="/site_media/media/ckeditor/"
CKEDITOR_UPLOAD_PATH = os.path.join(PROJECT_ROOT,"site_media" , "media/uploads").replace("\\",'/')
CKEDITOR_UPLOAD_PREFIX=os.path.join(PROJECT_ROOT,"/site_media/media/uploads").replace("/","\\")

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,
},
}


3:发布之前部署静态文件

python manage.py collectstatic


4:在 admin 里使用 ckeditor

models.py

from ckeditor.fields import RichTextField
class Course(models.Model):
coursecontent = RichTextField(verbose_name=_('coursecontent'))


5:在网页中使用 ckeditor

forms.py

from ckeditor.widgets import CKEditorWidget
class AddCourseForm(forms.ModelForm):
coursecontent = forms.CharField(label=_('coursecontent')   ,widget=CKEditorWidget())

如图:



6:问题

在 windows 下 会出现 下图 的问题 ,图片能上传 但是不能预览显示 ,查看 图片 的html代码 发现 路劲有问题 



研究了好长时间 发现 如下信息:
https://github.com/brentrojas/django-ckeditor/commit/ce41e5219c9cd8f4ea1d7d339499ca61bdab7d65

原来这是 windows下的bug

那么我们只要 在库中做出相应的修改即可

如下图:



在模板中 去掉 ckeditor 造成的 html 标签:

只需要做出如下修改:

{% autoescape off %}
{{courseinfo.coursecontent}}
{% endautoescape %}

至此,在django中可以正常使用 ckeditor了。

转载请注明出处!





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息