Django Rich Text Editor

Source: Internet
Author: User
Tags virtual environment

-------------------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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.