——————- Tinymce rich text editor
1. Download and install
1. Search and download “Django-TinymCE-2.4.0” from pypi
1. Download and install
1. Search and download “Django-TinymCE-2.4.0” from pypi
2. Decompress tar ZXVF Django-tinymce-2.4.0.tar. gz
3, go to the decompressed directory, work in the virtual environment, install:
python setup.py install
python setup.py install
2. Apply to the project
1. Add an editor application to INSTALLED_APPS in settings.py
INSTALLED_APPS = (
.
‘tinymce’,
)
1. Add an editor application to INSTALLED_APPS in settings.py
INSTALLED_APPS = (
.
‘tinymce’,
)
2. Add edit configuration items in settings.py
TINYMCE_DEFAULT_CONFIG = {
‘theme’: ‘advanced’,
‘width’: 600,
‘height’: 400,
}
TINYMCE_DEFAULT_CONFIG = {
‘theme’: ‘advanced’,
‘width’: 600,
‘height’: 400,
}
3. Configure in the root urls.py
urlpatterns = [
.
url(r’^tinymce/’, include(‘tinymce.urls’)),
]
urlpatterns = [
.
url(r’^tinymce/’, include(‘tinymce.urls’)),
]
4. Define model attributes in the application
from django.db import models
from tinymce.models import HTMLField
from django.db import models
from tinymce.models import HTMLField
class GoodInfo(models.Model):
.
gdetail = HTMLField()
.
gdetail = HTMLField()
3, custom use
1. Define the view Editor to display the editor and complete the submission
def editor(request):
return render(request, ‘other/editor.html’)
2. Configure the URL
urlpatterns = [
.
url(r’^editor/$’, views.editor, name=’editor’),
]
1. Define the view Editor to display the editor and complete the submission
def editor(request):
return render(request, ‘other/editor.html’)
2. Configure the URL
urlpatterns = [
.
url(r’^editor/$’, views.editor, name=’editor’),
]
3. Create the template 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’> This is a rich text editor </textarea>
<br>
< form =”submit” value=” submit” >
</form>
</body>
</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’> This is a rich text editor </textarea>
<br>
< form =”submit” value=” submit” >
</form>
</body>
</html>
Define the view detail, receive the request, and update the goodInfo object
def detail(request):
hname = request.POST[‘hname’]
gdetail = request.POST[‘gdetail’]
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()
goodinfo.hname = hname
goodinfo.gdetail = gdetail
goodinfo.save()
return render(request, ‘other/detail.html’, {‘goods’: goodinfo})
5. Add url entries
urlpatterns = [
.
url(r’^detail/$’, views.detail, name=’detail’),
]
urlpatterns = [
.
url(r’^detail/$’, views.detail, name=’detail’),
]
6. Define the template detail.html
<! DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
Name: {{goods. Gname}}
<hr>
{%autoescape off%}
{{goods.gdetail}}
{%endautoescape%}
</body>
</html>
<! DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
Name: {{goods. Gname}}
<hr>
{%autoescape off%}
{{goods.gdetail}}
{%endautoescape%}
</body>
</html>
For more free technical information: annalin1203