码迷,mamicode.com
首页 > Web开发 > 详细

html5、django上传文件

时间:2018-05-22 23:54:10      阅读:457      评论:0      收藏:0      [点我收藏+]

标签:http   html   django   上传文件   

前端代码:

<!DOCTYPE html>
<html>
<head>
<title>uploadFile</title>

</head>
<body>

    <form method="POST" action="/upload"  enctype="multipart/form-data">
        <input type="file" name="myFile">
        <input type="submit" value="提交" />
    </form>

</body>

</html>

后端代码:
def upload(request):
##request.FILES 为类字典类型,健为前段name指定的值,字典值为UploadFile对象,前端form中需要指定enctype="multipart/form-data"
##<input type="file" name="myFile">
uploadFileObj = request.FILES[‘myFile‘]
uploadFileName = uploadFileObj.name
uploadFileSize = uploadFileObj.size

##上传文件
with open(uploadFileName,"wb") as saveFile:
    for chunk in uploadFileObj.chunks():
        saveFile.write(chunk)

return HttpResponse(‘file upload OK‘)

html5、django上传文件

标签:http   html   django   上传文件   

原文地址:http://blog.51cto.com/9429042/2119261

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