Examples of adding Rich Text to Django content

Source: Internet
Author: User

Examples of adding Rich Text to Django content

Rich Text is missing, which is too simple to be viewed and read.

A feasible method is recorded as follows:

1-download the third-party Rich Text KindEditor and connect to http://kindeditor.net/down.php?baidu.

2-decompress the package to static/js under the Django project ,:

No config. js by default. You need to create config. js by yourself. For details, refer to the official website of KindEditor or the following code:

KindEditor. ready (function (K) {K. create ('textarea ', {width: 700, height: 200,}) ;}); # Pay attention to the reference of textarea. width and height respectively set the width and height of the text box.

3-in your admin. py, you need to add the Rich Text Category Code Format as follows:

class ArticleAdmin(admin.ModelAdmin):  class Media:   js={    '/static/js/kindeditor/lang/zh-CN.js',    '/static/js/kindeditor/kindeditor-all-min.js',    '/static/js/kindeditor/config.js',   }  admin.site.register(Article, ArticleAdmin)

4-now, after refreshing, you can see that the rich text editing function is added to the content area. If you do not need to carefully check the above steps, do not modify the copy code if you are not skilled.

5-in the end, I encountered a small pitfall. The html syntax is displayed when the page in the format is added and html escaping needs to be disabled,

The method is to modify it in the template:

Change {article. content}

{Article. content | safe}. Another method is:

{% Autoescape off %}

{Article. content }}
{% Endautoescape %}

After modification:

6-you also need to set the path and related configuration for file upload, as described in the next record.

The example of adding Rich Text in Django content above is all the content shared by xiaobian. I hope you can give us a reference and support the help house.

Related Article

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.