django中集成富文本编辑器

django中集成富文本编辑器,第1张

文本即具备丰富样式格式的文本。可以是包含了HTML语法格式的字符串。为了快速简单的让用户能够在页面中编辑带html格式的文本,引入富文本编辑器

富文本编辑器:ueditor、ckeditor、kindeditor

在INSTALLED_APPS中添加

在settings/dev.py中添加

在总路由中添加

ckeditor提供了两种类型的Django模型类字段

修改应用/models.py里面的字段信息,记得要重新数据迁移

效果图

一、下载安装

python setup.py install

二、

1.将tinymce/static/tiny_mce文件夹放到your_project/static目录下;

2.将tinymce文件夹放到your_project目录下

三、在urls.py文件中加入:

url(r'^tinymce/',include('tinymce.urls')),

四、在settings.py文件中加入:

INSTALLED_APPS = (

'tinymce',

五、在settings.py文件中加入:

TINYMCE_JS_URL=MEDIA_URL+'/static/tiny_mce/tiny_mce_src.js'

TINYMCE_JS_ROOT=MEDIA_ROOT+'/static/tiny_mce/'

六、在settings.py文件中加入:

TINYMCE_DEFAULT_CONFIG = {

'theme': "advanced",

'theme_advanced_toolbar_location' : "top",

'theme_advanced_toolbar_align' : "left",

‘width’: 600,

‘height’: 400,

}

七、修改models.py文件

from your_project.tinymce import models as tinymce_models

class Post(models.Model):

body=tinymce_models.HTMLField()

这个几乎不需要配置啊。 你先把tineymce安装好。这个看它的教程中的installation就可以搞定。

<!-- Place inside the <head> of your HTML -->

<script type="text/javascript" src="<your installation path>/tinymce/tinymce.min.js"></script>

<script type="text/javascript">

tinymce.init({

    selector: "textarea"

 })

</script>

<!-- Place this in the body of the page content -->

<form method="post">

    <textarea></textarea>

</form>

你只需要将form中的action写成你的django对应的处理的path就可以了。

内容加载,可能就需要用template了。 


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11618772.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存