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

django文件批量上传-简写版

时间:2016-08-15 17:15:05      阅读:214      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!