码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-08-17 11:03:18      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:ext   extra   Edito   func   session   title   文本   文章   epo   

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,{
                        width:"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>

 

 

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

标签:ext   extra   Edito   func   session   title   文本   文章   epo   

原文地址:https://www.cnblogs.com/person1-0-1/p/11367465.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!