-------------------TinyMCE Rich Text editor
1. Download and install
1, search and download "django-tinymce-2.4.0" on website PyPI website
2, Decompression: Tar zxvf django-tinymce-2.4.0.tar.gz
3, enter the extracted directory, work in the virtual environment, installation:
Python setup.py Install
2. Apply to Project
1. Add editor app for Installed_apps in settings.py
Installed_apps = (
...
' TinyMCE ',
)
2. Add edit configuration item in settings.py
Tinymce_default_config = {
' Theme ': ' Advanced ',
' Width ': 600,
' Height ': 400,
}
3. Configuring in the root urls.py
Urlpatterns = [
...
URL (r ' ^tinymce/', include (' Tinymce.urls ')),
]
4. Define the properties of the model in the application
From django.db import Models
From Tinymce.models import Htmlfield
Class Goodinfo (models. Model):
...
Gdetail = Htmlfield ()
3. Custom Use
1. Define the View editor to display the editors and complete the submission
def editor (request):
return render (Request, ' other/editor.html ')
2. Configure URLs
Urlpatterns = [
...
URL (r ' ^editor/$ ', Views.editor, name= ' editor '),
]
3. Create Template editor.html
<! DOCTYPE html>
<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>
<body>
<form method= "POST" action= "/detail/" >
<input type= "text" name= "Hname" >
<br>
<textarea name= ' Gdetail ' > This is a rich text editor </textarea>
<br>
<input type= "Submit" value= "Submission" >
</form>
</body>
4. Define the view detail, receive the request, and update the Goodinfo object
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})
5. Add URL entry
Urlpatterns = [
...
URL (r ' ^detail/$ ', views.detail, name= ' detail '),
]
6. Define Template detail.html
<! DOCTYPE html>
<title></title>
<body>
Name: {{Goods.gname}}
{%autoescape off%}
{{Goods.gdetail}}
{%endautoescape%}
</body>
Django Rich Text Editor