下载安装
tar zxvf django-tinymce-2.4.0.tar.gz
python setup.py install
应用到项目中
INSTALLED_APPS = (
...
'tinymce',
)
TINYMCE_DEFAULT_CONFIG = {
'theme': 'advanced',
'width': 600,
'height': 400,
}
urlpatterns = [
...
url(r'^tinymce/', include('tinymce.urls')),
]
from django.db import models
from tinymce.models import HTMLField
class HeroInfo(models.Model):
...
hcontent = HTMLField()
自定义使用
def editor(request):
return render(request, 'other/editor.html')
urlpatterns = [
...
url(r'^editor/$', views.editor, name='editor'),
]
<!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="/content/">
<input type="text" name="hname">
<br>
<textarea name='hcontent'>哈哈,这是啥呀</textarea>
<br>
<input type="submit" value="提交">
</form>
</body>
</html>
def content(request):
hname = request.POST['hname']
hcontent = request.POST['hcontent']
heroinfo = HeroInfo.objects.get(pk=1)
heroinfo.hname = hname
heroinfo.hcontent = hcontent
heroinfo.save()
return render(request, 'other/content.html', {'hero': heroinfo})
urlpatterns = [
...
url(r'^content/$', views.content, name='content'),
]
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
姓名:{{hero.hname}}
<hr>
{%autoescape off%}
{{hero.hcontent}}
{%endautoescape%}
</body>
</html>