当前位置:脚本大全 > > 正文

django菜单动态生成(django富文本编辑器的实现示例)

时间:2021-10-21 07:23:04类别:脚本大全

django菜单动态生成

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菜单动态生成(django富文本编辑器的实现示例)

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

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

    上一篇下一篇

    猜您喜欢

    热门推荐