脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - django富文本编辑器的实现示例

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

2021-06-14 00:53Pengxingwang Python

这篇文章主要介绍了django富文本编辑器的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

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

使用方法

1.安装

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

?
1
python setup.py install

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

?
1
pip install djangoueditor

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

?
1
2
3
4
installed_apps = [
 ...
 'djangoueditor'
]

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

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

4.在 modal 使用

?
1
2
3
4
5
# 引入 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 文件里面,把这个字段渲染出来

?
1
2
3
{% autoescape off %}
 {{ course.detail }}
 {% endautoescape %}

6.在 xadmin 中使用

?
1
2
#在该模块的 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

?
1
2
3
4
5
6
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行处注 释掉,就能正常运行了)
)

示例

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

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

原文链接:http://blog.beastxw.wang/2019/04/10/django富文本编辑器/#more

延伸 · 阅读

精彩推荐