• python-Web-django-富文本编辑器


    views:

    def gbook(request):
        ''''''
        text = request.POST.get('text')
        soup = BeautifulSoup(text, "html.parser")  # 通过字符串创建    
        BeautifulSoup对象,即将字符串转为对象,然后调用对象里的相关方法
        # for tag in soup.find_all():
        #     if tag.name == 'script':
        #         tag.documpose()
        # 摘要
        description = soup.text[0:50] + '...'
    
    def upload(request):
        '''编辑器文本数据保存'''
        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',{
                            "800",
                            height:"600",
                            resizeType:0,
                            uploadJson:"/back/article/upload/",
                            extraFileUploadParams:{
                                csrfmiddlewaretoken:"{{ csrf_token }}"
                            },
                            filePostName:"img"//上传图片的名称
                        });
                        // 点击事件
                        K('input[name="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>

     
  • 相关阅读:
    向对象(OO)程序设计
    gVim安装vim-template插件后提示Undefined variable vim_template_subtype/Press ENTER or type command to continue
    基于JQuery easyui,gson的批量新增/修改和删除-servlet版
    Java正则表达式-匹配正负浮点数
    自己写的ORM工具
    秋色园学习测试项目
    把aspx页面生成的cs文件放到其他类库中,以实现对其的封装操作.
    杭州蚂蚁中台技术部-22届应届生-校招实习
    博客园开博
    开发随手记
  • 原文地址:https://www.cnblogs.com/person1-0-1/p/11367465.html
Copyright © 2020-2023  润新知