介绍
富文本:Rich Text Format(RTF),是有微软开发的跨平台文档格式,大多数的文字处理软件都能读取和保存RTF文档,其实就是可以添加样式的文档,和HTML有很多相似的地方
django的插件
pip install django-tinymce
用处
用处大约有两种
在后台管理中使用
在页面中使用,通常用来作博客
后台中使用
配置settings.py文件
INSTALLED_APPS 添加 tinymce 应用
添加默认配置
1 2 3 4 5 6 7 8 9
| TINYMCE_DEFAULT_CONFIG = {
'theme':'advanced',
'width':800,
'height':600,
}
|
创建模型类
1 2 3
| from tinymce.models import HTMLField class Blog(models.Model): sBlog = HTMLField()
|
配置站点
admin.site.register
在视图中使用
1 2 3 4 5 6 7 8 9 10 11 12 13
| 使用文本域盛放内容 <form method='post' action='url'> <textarea></textarea> </form> 在head中添加script <script src='/static/tiny_mce/tiny_mce.js'></script> <script> tinyMCE.init({ 'mode':'textareas', 'theme':'advanced', 'width':800,'height':600, }) </script>
|
实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| {% load static %} <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>EditBlog</title> <script type="text/javascript" src="/static/tiny_mce/tiny_mce.js"></script> <script type="text/javascript">
tinyMCE.init({ "mode": "textareas", "theme": "advanced", "width": 800, "height": 600 })
</script> </head> <body>
<form action="{% url 'app:edit_blog' %}" method="post"> {% csrf_token %} <textarea name="content">
</textarea>
<button>保存</button> </form>
</body> </html>
|