当前位置: 移动技术网 > IT编程>脚本编程>Python > django富文本编辑器的实现示例

django富文本编辑器的实现示例

2019年06月08日  | 移动技术网IT编程  | 我要评论

东阳一周天气,非洲角蝰,伏虎岩

最近一段时间都在学django,现在的网站基本都要使用到富文本编辑器,今天就记录下使用django的管理后台的一个富文本编辑器的第三方库 djangoueditor

使用方法

1.安装

方法一:将github整个源码包下载回家,在命令行运行:

python setup.py install

方法二:使用pip工具在命令行运行(推荐):

pip install djangoueditor

2.在 settings.py的install_apps里面增加djangoueditor app

installed_apps = [
 ...
 'djangoueditor'
]

3.配置urls 在urls.py 里添加路由

# 富文本
path('ueditor/', include('djangoueditor.urls')),

4.在 modal 使用

# 引入 ueditorfield
from djangoueditor.models import ueditorfield
# 使用
class demo(model.model):
 detail = ueditorfield(verbose_name=u'详情', width=600, height=300, imagepath="courses/ueditor/", filepath="courses/ueditor/", default='')

5.在template里的html 文件里面,把这个字段渲染出来

{% autoescape off %}
 {{ course.detail }}
 {% endautoescape %}

6.在 xadmin 中使用

#在该模块的 xadmin.py 中加上
style_fields = {"detail": "ueditor"}

问题

我是在虚拟环境里起的项目,这样安装好之后,报了一个

typeerror: render() got an unexpected keyword argument 'renderer'

解决

需要修改虚拟环境下的:boundfield.py文件: .virtualenvs/虚拟环境文件/lib/python3.x/site-packages/django/forms/boundfield.py

  return widget.render(
   name=self.html_initial_name if only_initial else self.html_name,
   value=self.value(),
   attrs=attrs,
   # renderer=self.form.renderer,(93行处注 释掉,就能正常运行了)
  )

示例

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网