-------------------tinymce富文本編輯器
一、下載安裝
一、在網站pypi網站搜索並下載"django-tinymce-2.4.0"javascript
二、解壓:tar zxvf django-tinymce-2.4.0.tar.gzhtml
三、進入解壓後的目錄,工做在虛擬環境,安裝:
python setup.py installjava
二、應用到項目
一、在settings.py中爲INSTALLED_APPS添加編輯器應用
INSTALLED_APPS = (
...
'tinymce',
)python
二、在settings.py中添加編輯配置項
TINYMCE_DEFAULT_CONFIG = {
'theme': 'advanced',
'width': 600,
'height': 400,
}django
三、在根urls.py中配置
urlpatterns = [
...
url(r'^tinymce/', include('tinymce.urls')),
]編輯器
四、在應用中定義模型的屬性
from django.db import models
from tinymce.models import HTMLFieldide
class GoodInfo(models.Model):
...
gdetail = HTMLField()post
三、自定義使用
一、定義視圖editor,用於顯示編輯器並完成提交
def editor(request):
return render(request, 'other/editor.html')網站
二、配置url
urlpatterns = [
...
url(r'^editor/$', views.editor, name='editor'),
]url
三、建立模板editor.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src='/static/tiny_mce/tiny_mce.js'></script>
<script type="text/javascript">
tinyMCE.init({
'mode':'textareas',
'theme':'advanced',
'width':400,
'height':100
});
</script>
</head>
<body>
<form method="post" action="/detail/">
<input type="text" name="hname">
<br>
<textarea name='gdetail'>這是一個富文本編輯器</textarea>
<br>
<input type="submit" value="提交">
</form>
</body>
</html>
四、定義視圖detail,接收請求,並更新goodInfo對象
def detail(request):
hname = request.POST['hname']
gdetail = request.POST['gdetail']
goodinfo = GoodInfo.objects.get(pk=1)
goodinfo.hname = hname
goodinfo.gdetail = gdetail
goodinfo.save()
return render(request, 'other/detail.html', {'goods': goodinfo})
五、添加url項
urlpatterns = [
...
url(r'^detail/$', views.detail, name='detail'),
]
六、定義模板detail.html<!DOCTYPE html><html><head><title></title></head><body>姓名:{{goods.gname}}<hr>{%autoescape off%}{{goods.gdetail}}{%endautoescape%}</body></html>