首页 > Web开发 > 详细

django文件批量上传-简写版

时间:2016-08-15 17:14:14      阅读:777      评论:0      收藏:0      [点我收藏+]

模板中创建表单

<form method=‘post‘ enctype=‘multipart/form-data‘ action=‘/upload/‘>
    <input type=‘file‘ name=‘upload_img‘/>
    <input type=‘file‘ name=‘upload_img‘/>    
    <input type=‘submit‘ value=‘submit‘>
</form>

在urls中到处一个upload地址

 url(r^upload/$,upload),

最后写控制器

@csrf_exempt
def upload(req):
    if req.method==POST:
        files=req.FILES.getlist(upload_img)
        for f in files:
            print f.name
            with open(‘/...url.../+f.name,wb+) as des:
                for chunk in f.chunks():
                    des.write(chunk)
    return render_to_response(index.html)

完毕

 

django文件批量上传-简写版

原文:http://www.cnblogs.com/zboy/p/5773599.html

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