Added Rich Text function for Django content, django content text
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 are respectively set for 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.