ueditor版本python3_【MAC-Django-UEditor】python3之富文本编辑器

踩了很多坑,最后还是踩过了,很无奈!!先上最后的效果图

图片上传

图片显示,文本编辑

1.DjangoUeditor-安装

我使用的是python3,首先用pip安装DjangoUeditor,

pip3 install DjangoUeditor //然后,坑开始了,欢迎补充坑

下载DjangoUeditor3

首先安装后的DjangoUeditor版本,代码没有更新,只是适配了python2,你用python3当然要出现问题了!!!!!!

请点击,然后下载 https://github.com/twz915/DjangoUeditor3/

替换部分不适配python3的DjangoUeditor

找到DjangoUeditor的位置,替换(DjangoUeditor3里面的DjangoUeditor文件夹替换到本地的DjangoUeditor)【替换后还需要修改一个类的头文件引入,看具体报错找位置,修改起来很简单】

Import sys

sys.path //找到python3 的本地下载库

我本地的位置

2.django使用DjangoUeditor-代码

Setting.py

INSTALLED_APPS = (

#........

'DjangoUeditor',

)

//上传路径(很重要)

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

UEDITOR_SETTINGS={

"toolbars":{ #定义多个工具栏显示的按钮,允行定义多个

"name1":[[ 'source', '|','bold', 'italic', 'underline']],

"name2",[]

},

"images_upload":{

"allow_type":"jpg,png", #定义允许的上传的图片类型

"max_size":"2222kb" #定义允许上传的图片大小,0代表不限制

},

"files_upload":{

"allow_type":"zip,rar", #定义允许的上传的文件类型

"max_size":"2222kb" #定义允许上传的文件大小,0代表不限制

},,

"image_manager":{

"location":"" #图片管理器的位置,如果没有指定,默认跟图片路径上传一样

},

}

urls.py

url(r'^ueditor/',include('DjangoUeditor.urls' )),

# 如果不设置,上传后将看不到图片

# use Django server /media/ files

from django.conf import settings

if settings.DEBUG:

from django.conf.urls.static import static

urlpatterns += static(

settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

models

from DjangoUeditor.models import UEditorField

class Blog(models.Model):

Name=models.CharField(max_length=100,blank=True)

Content=UEditorField('内容 ',height=100,width=500,default='test',imagePath="uploadimg/",imageManagerPath="imglib",toolbars='mini',options={"elementPathEnabled":True},filePath='upload',blank=True)

forms

from DjangoUeditor.forms import UEditorField

class TestUEditorForm(forms.Form):

Description=UEditorField("描述",initial="abc",width=600,height=800)

views

from blog.forms.TestUeditorModelForm import TestUEditorForm

form = TestUEditorForm()

return render_to_response('topic/topicHome.html',{"form": form})

html

先运行 python3 manage.py collectstatic

......

{{ form.media }} #这一句会将所需要的CSS和JS加进来。

......

{{ form }}

感概一下,python学习真的资料太少了,坑太多了,很多地方的代码和逻辑都是我东平西凑补全的。另外我严重怀疑,很多写博客的绝对自己项目都没跑起来,然后就把我带到了深坑里,难受!!!!!。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值