您好,登錄后才能下訂單哦!
視圖函數
CONTENT = ""
from app01.forms import ArticleForm
def wangzhe(request):
if request.method == "GET":
obj = ArticleForm()
return render(request,'wangzhe.html',{'obj':obj})
else:
obj = ArticleForm(request.POST)
if obj.is_valid():
content = obj.cleaned_data['content']
global CONTENT
CONTENT = content
print(content)
return HttpResponse('...')
def see(request):
return render(request,'see.html',{'con': CONTENT})
def upload_img(request):
import os
upload_type = request.GET.get('dir')
file_obj = request.FILES.get('imgFile')
file_path = os.path.join('static/imgs',file_obj.name)
with open(file_path,'wb') as f:
for chunk in file_obj.chunks():
f.write(chunk)
dic = {
'error': 0,
'url': '/' + file_path,
'message': '錯誤了...'
}
import json
return HttpResponse(json.dumps(dic))
前端頁面
<body>
<form method="POST" action="/wangzhe.html" novalidate>
{% csrf_token %}
<p>
文章標題
{{ obj.title }}
</p>
<div>
<div>文章內容</div>
<div>
{{ obj.content }}
</div>
</div>
<input type="submit" value="提交" />
</form>
<script src="/static/kindeditor-4.1.10/kindeditor-all.js"></script>
<script>
KindEditor.create("#i1",{
width: "700px",
height: "300px",
resizeType:1,
uploadJson: '/upload_img.html',
extraFileUploadParams:{
"csrfmiddlewaretoken":"{{ csrf_token }}"
}
})
</script>
</body>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。