最近一段时间都在学django,现在的网站基本都要使用到富文本编辑器,今天就记录下使用django的管理后台的一个富文本编辑器的第三方库 DjangoUeditor
使用方法
1.安装
方法一:将github整个源码包下载回家,在命令行运行:
方法二:使用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行处注 释掉,就能正常运行了)
- )
示例

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