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>