1. 程式人生 > >django編輯框實現

django編輯框實現

port csrf dumps static init logs item console ID

一些常用的:

  • CKEditor
  • UEEditor
  • TinyEditor
  • KindEditor

下載:

http://kindeditor.net/down.php

使用方法:

<textarea name="comment" id="comment"></textarea>
<script>
$(function () {
 initKindEditor();
});
function initKindEditor() {
    var kind = KindEditor.create(
        ‘#comment‘, {
            width: ‘100%‘ ,
            height: ‘300px‘,
           uploadJson:‘/uploadimg‘,
extraFileUploadParams: {
‘csrfmiddlewaretoken‘: ‘{{ csrf_token }}‘
} ) } </script>

  或者:

var editor;
        KindEditor.ready(function (K) {
            editor = K.create(‘textarea[name="comment"]‘, {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    ‘fontname‘, ‘fontsize‘, ‘|‘, ‘forecolor‘, ‘hilitecolor‘, ‘bold‘, ‘italic‘, ‘underline‘,
                    ‘removeformat‘, ‘|‘, ‘justifyleft‘, ‘justifycenter‘, ‘justifyright‘, ‘insertorderedlist‘,
                    ‘insertunorderedlist‘, ‘|‘, ‘emoticons‘, ‘image‘, ‘link‘],
                    uploadJson:‘/uploadimg‘,  #文件上傳功能
extraFileUploadParams: {
‘csrfmiddlewaretoken‘: ‘{{ csrf_token }}‘
}); });

後臺返回

def uploadimg(request):
    import json
    dic = {
        ‘error‘: 0,
        ‘url‘: ‘/static/img/4.jpg‘,
        ‘message‘: ‘錯誤了...‘
    }

    return HttpResponse(json.dumps(dic))

  

詳細參數

http://kindeditor.net/docs/option.html

內容提交

 $(‘#commentsubmit‘).click(function () {
     console.log(editor.html())
 })

相關鏈接:

https://www.cnblogs.com/wupeiqi/p/6307554.html

django編輯框實現