python-Web-django- rich text editor

views:

DEF gbook (Request):
     '' '' '' 
    text = request.POST.get ( ' text ' ) 
    Soup = BeautifulSoup (text, " html.parser " )   # create a string by     
    BeautifulSoup the object, the object is about to turn a string , then call an object method in the related
     # for Tag in soup.find_all (): 
    #      IF tag.name == 'Script': 
    #          tag.documpose () 
    # summary 
    Description soup.text = [0:50] + ' . .. ' 

DEF Upload (Request):
     ' '' editor text data storage '' '
    print(0)
    if request.FILES.get('img'):
        '''有图片上传'''

        img_obj = request.FILES.get('img')
        # 保存图片地址
        print(1)
        path = os.path.join(settings.MEDIA_ROOT,"add_article_img",img_obj.name)
        with open(path,'wb') as f:
            for i in img_obj:
                f.write(i)
        response = {
            "error": 0,
            "url": "/media/add_article_img/%s" % img_obj.name
        }
        print(2)
        return HttpResponse(json.dumps(response))

 

html:

<script type="text/javascript" src="/static/back/kindeditor/kindeditor-all.js"></script>
    <script>
            KindEditor.ready(function(K) {
                    window.editor = K.create('#content',{
                        width:"800",
                        height:"600",
                        resizeType:0,
                        uploadJson:"/ the Back / Article This article was / the Upload / " , 
                        extraFileUploadParams: { 
                            csrfmiddlewaretoken: " {{}} csrf_token " 
                        }, 
                        filePostName: " img " // name to upload your pictures 
                    });
                     // click event 
                    K ( ' the INPUT [name =" the dosubmit "] ' ) .click ( function (E) { 

                        var title = $ .trim ($ ( " #title " ) .val ());
                         var time = $.trim($("#time").val());
                        var articleid = $.trim($("#articleid").val());
                        var content = $("#content").html();
                        var text = editor.html();
                        $.post("/app01/gbook/",{
                            "text": text,
                            "title": title,
                            'time':time,
                            'articleid':articleid,
                            'content':content,
                            "memberid": {{ request.session.member_id }},
                            "dosubmit": 1,
                            "csrfmiddlewaretoken": "{{ csrf_token }}"
                        }, function (data) {
                            if (data['s'] == 1) {
                                layer.msg(data['info']);
                                return false;

                            } else {
                                //失败
                                layer.msg(data['info']);
                            }
                            return false;
                        }, "json");
                        });
            });

</script>




<p>
<
span class="tnr">文章内容:</span> <div></div>
<textarea id="content" name="content" cols="60" rows="40" id="content" >{{ article_obj.article_content }}</textarea> </p>

  <p>
  <input type="button" name="dosubmit" value="马上发布" id="st"/>
  </p>

 

 

Guess you like

Origin www.cnblogs.com/person1-0-1/p/11367465.html