首页 > Web开发 > 详细

html5、django上传文件

时间:2018-05-22 23:46:15      阅读:286      评论:0      收藏:0      [点我收藏+]
前端代码:

<!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://blog.51cto.com/9429042/2119261

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!